Link to home
Start Free TrialLog in
Avatar of sharingsunshine
sharingsunshineFlag for United States of America

asked on

Prestashop Array Assign() To Smarty

I had this question after viewing Add PHP  Page To Prestashop 1.5.6.

I am trying to assign a variable to a smarty .tpl file for output

I have this code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Count Checks</title>
</head>
<body>
<h1>Count Checks</h1>
<form method="post">
  
    
General Health & Vitality<br />
Please check all that apply<br />
Illness More Than Twice A Year:<input type="checkbox" name="symptom[]" value='illness'><br />
Body Odor and/or Bad Breath:<input type="checkbox" name="symptom[]" value='odor'><br />
Difficulty Digesting Certain Foods:<input type="checkbox" name="symptom[]" value='digesting'><br />
Less Than 3 Servings Of Fruits And Veggies Daily:<input type="checkbox" name="symptom" value='fruits'><br />
Monthly Female Concerns:<input type="checkbox" name="symptom[]" value='female'><br />
Recent Or Frequent Use Of Antibiotics:<input type="checkbox" name="symptom[]" value='antibiotics'><br />
Regular Consumption Of Alcohol:<input type="checkbox" name="symptom" value='alcohol'><br />
Gum Problems Or Redness On Nose:<input type="checkbox" name="symptom[]" value='gums'><br />
Food Allergies:<input type="checkbox" name="symptom" value='allergies'><br />
Puffiness Under Eyes:<input type="checkbox" name="symptom[]" value='eyes'><br />
Smoking:<input type="checkbox" name="symptom[]" value='smoking'><br />
Poor Concentration or Memory:<input type="checkbox" name="symptom[]" value='memory'><br />  
Heavy Coating On Tongue:<input type="checkbox" name="symptom[]" value='coating'><br />-->
Belching or Gas After Meals:<input type="checkbox" name="symptom" value='belching'><br />
Stressful Lifestyle:<input type="checkbox" name="symptom" value='stress'><br />
Skin/Complexion Problems:<input type="checkbox" name="symptom[]" value='skin'><br />
Consume Sweets More Than 3 Times A Week:<input type="checkbox" name="symptom" value='sweets'><br />
Daily Consumption Of Dairy Products:<input type="checkbox" name="symptom" value='dairy'><br />
Feeling Down, Uninterested or Moody:<input type="checkbox" name="symptom[]" value='moody'><br />
Difficulty Getting To Sleep, Lack Of Sleep:<input type="checkbox" name="symptom[]" value='sleep'><br />
Menopausal Concerns:<input type="checkbox" name="symptom[]" value='menopausal'><br />
Frequent Urination Or Urinary Concerns:<input type="checkbox" name="symptom[]" value='frequent'><br />
Age-Related Health Problems:<input type="checkbox" name="symptom[]" value='age'><br />
Sore Or Painful Joints:<input type="checkbox" name="symptom[]" value='sore'><br />
Difficulty Maintaining Ideal Weight:<input type="checkbox" name="symptom[]" value='weight'><br />
Lack Of Energy Or Endurance:<input type="checkbox" name="symptom[]" value='energy'><br />
Routinely Eat Refined Grains:<input type="checkbox" name="symptom" value='refined'><br />
Heavyy Mucous Production Or Feeling Congested:<input type="checkbox" name="symptom[]" value='mucous'><br />
1 Or Fewer Bowel Movements Per Day:<input type="checkbox" name="symptom[]" value='bowels'><br />
Weak Knees, Ankles Or Back:<input type="checkbox" name="symptom[]" value='weak'><br />
Low Sex Drive:<input type="checkbox" name="symptom[]" value='sex'><br />
Brittle Or Easily Broken Fingernails:<input type="checkbox" name="symptom[]" value='brittle'><br /> 
Dry, Damaged Or Dull Hair:<input type="checkbox" name="symptom[]" value='hair'><br />
Consume Fried Foods Greater Than 3 Times A Week:<input type="checkbox" name="symptom" value='fried'><br />
Frequently Feeling Fearful or Timid:<input type="checkbox" name="symptom[]" value='fearful'><br />  
Cold Hands And Feet:<input type="checkbox" name="symptom[]" value='cold'><br />
Muscle Cramps Or Spasms:<input type="checkbox" name="symptom[]" value='cramps'><br />
Exposure To Air Pollution:<input type="checkbox" name="symptom[]" value='pollution'><br />
Daily Consumption Of Caffeinated Beverages:<input type="checkbox" name="symptom" value='caffeinated'><br />
Shallow Or Difficult Breathing:<input type="checkbox" name="symptom[]" value='shallow'><br />
Restless Sleep or Waking Up Frequently:<input type="checkbox" name="symptom" value='restless'><br />
Recurrent Yeast Or Fungal Infections:<input type="checkbox" name="symptom[]" value='yeast'><br />
Weak Bones, Teeth Or Cartilage:<input type="checkbox" name="symptom[]" value='weak'><br />
Feeling Anxious or Worried: <input type="checkbox" name="symptom" value='anxious'/>
Feeling Irritable or Easily Angered:<input type="checkbox" name="symptom" value='angered'/>    
Don't Exercise Regularly:<input type="checkbox" name="symptom[]" value='exercise'><br />
Respiratory Concerns:<input type="checkbox" name="symptom[]" value='concerns'><br />
<!--Drink Chlorinated Water:<input type="checkbox" name="symptom[]" value='chlorinated'><br />
Routinely Use Commercial Personal Care Items:<input type="checkbox" name="symptom[]" value='personal_care'><br />
Routinely Use OTC Medications And Painkillers:<input type="checkbox" name="symptom[]" value='OTC'><br />
Routinely Use Commercial Cleaners Or Laundry Products:<input type="checkbox" name="symptom[]" value='laundry'><br />
Routinely Use Prescription Medicine:<input type="checkbox" name="symptom[]" value='prescription'><br />-->
<input type="submit" >
</form>


<?php
  

// array of symptoms/values ( digestive, hepatic, intestinal)
$illness = array(0,0,0,0,0,3,3,0,0,0);
$odor = array(1,0,3,0,0,0,1,1,0,0);
$difficulty = array(3,2,0,0,0,1,0,0,0,0);
$fruits = array(1,0,2,1,0,2,0,1,0,0);
$female = array(0,2,1,0,0,0,0,1,3,0);
$antibiotics = array(0,0,2,0,0,3,1,0,0,0);
  $coating = array(3,0,1,0,0,1,1,0,0,0);
  $eyes = array(0,0,0,0,0,0,0,0,0,0);
  $sleep = array(0,2,0,0,1,0,0,0,0,0);
  $digesting = array(3,2,0,0,0,1,0,0,0,0);
  $fruits = array(1,0,2,1,0,2,0,1,0,0);
  $female = array(0,2,1,0,0,0,0,1,3,0);
  $alcohol = array(0,5,0,0,1,0,0,0,1,0);
  $gums = array(0,0,0,2,0,0,0,0,0,0);
  $allergies = array(3,2,0,0,0,1,2,0,0,0);
  $smoking = array(0,1,0,3,2,2,5,0,0,0);
  $memory = array(0,0,0,2,1,0,0,0,1,0);
  $belching = array(3,0,1,0,0,0,0,0,0,0);
  $stress = array(0,0,0,3,2,2,0,0,1,0);
  $skin = array(0,2,2,0,0,0,0,2,1,2);
  $sweets = array(0,0,0,0,0,1,0,0,2,0);
  $dairy = array(0,0,2,0,0,0,2,0,0,0);
  $moody = array(0,3,1,0,3,0,0,0,1,0);
  $menopausal = array(0,1,0,0,1,0,0,0,1,2);
  $urinary = array(0,0,0,0,0,0,0,4,0,0);
  
  $age = array(1,0,0,2,0,1,0,0,1,2);
  $sore = array(0,0,1,0,0,1,0,1,0,3);
  $weight = array(1,0,0,0,1,0,0,1,1,0);
  $energy = array(0,0,0,1,0,2,1,0,1,0);
  $refined = array(1,0,2,1,0,0,0,3,0,1);
  $mucous = array(1,0,1,0,0,0,2,0,0,0);
  $bowels = array(1,1,3,0,1,0,1,0,0,0);
  $weak = array(0,0,0,0,0,0,0,2,0,3);
  $sex = array(0,0,0,1,1,0,0,0,2,0);
  $brittle = array(1,0,0,0,0,0,0,0,0,2);
  
  $dull = array(1,0,0,0,0,0,0,0,1,2);
  $fried = array(1,2,0,3,1,0,0,0,0,0);
  $fearful = array(0,0,0,0,2,0,0,2,1,0);
  $cramps = array(0,0,0,0,2,0,0,0,0,1);
  $pollution = array(0,0,0,0,0,1,2,0,0,0);
  $caffeinated = array(0,0,0,0,1,0,0,0,1,2);
  $shallow = array(0,0,0,0,0,1,2,0,0,0);
  $restless = array(0,2,0,0,1,0,0,1,1,0);
  $yeast = array(1,0,2,0,0,2,1,1,0,0);
  $anxious = array(1,0,0,0,3,0,0,0,1,0);
  
  $angered = array(0,2,0,1,1,0,0,0,2,0);
  $exercise = array(0,0,0,2,0,0,0,0,0,2);
  $concerns = array(0,0,1,0,0,1,3,0,0,0);
  
  // initialize values 
$digestive = 0;
  //$data['hepatic'] = array(0,0,2,0,2,0,5,0,2,0,1,0,0,0,0,2,0,0,3,2,1,0,0,0,0,0,0,0,1,0,0,0,0,2,0,0,0,0,0,0,2,0,0,0,2,0,0);
$hepatic = 0;
$intestinal = 0;
$circulatory = 0;
$nervous = 0;
$immune = 0;
$respiratory = 0;
$urinary = 0;
$glandular = 0;
$structural = 0;
  //print_r ($data['digestive']);

/*
if( empty($_POST["illness"] ) ) {
  $illness = 0;
}elseif ( empty($_POST["difficulty"] ) ){
  $difficulty = 0;
}elseif ( empty($_POST["odor"] ) ){
  $odor = 0;
}elseif ( empty($_POST["antibiotics"] ) ){
  $antibiotics = 0;
}else { 
  $post = array('illness','difficulty','odor','antibiotics'); 
}*/

  //print_r($data);


  
// simulate your post
//$post = array('illness','difficulty','odor','antibiotics');
  $post = $_POST['symptom'];
 
  
foreach   ($post as $value) {
    $value = $$value;
    // use variable variables to match what is posted with the vairable name http://php.net/manual/en/language.variables.variable.php
    $digestive = $digestive +$value[0];
    $hepatic = $hepatic +$value[1];
  $intestinal = $intestinal +$value[2];
  $circulatory = $circulatory +$value[3];
    $nervous = $nervous +$value[4];
  $immune = $immune +$value[5];
  $respiratory = $respiratory +$value[6];
  $urinary = $urinary +$value[7];
  $glandular = $glandular +$value[8];
  $structural = $structural +$value[9];
 
} 

// place totals in an array
$totals = array(
    'digestive' => $digestive,
    'hepatic' => $hepatic,
    'intestinal' => $intestinal,
  'circulatory' => $circulatory,
  'nervous' => $nervous,
  'immune' => $immune,
  'respiratory' => $respiratory,
  'urinary' => $urinary,
  'glandular' => $glandular,
  'structural' => $structural
);
   
// sort the array http://php.net/manual/en/array.sorting.php
arsort($totals);

// display the array sorted
foreach ($totals as $key => $value) {
    echo "$key = $value<br>";
}
  $smarty->assign('totals', $totals);
$smarty->display('/themes/warehouse/assessment.tpl');

?>

</pre>
</body>
</html>

Open in new window


This is the error I am getting.

PHP Fatal error:  Call to a member function assign() on null in /data/web/abc.com/override/controllers/front/AssessmentController.php on line 152

Open in new window


This is what is on line 152
$smarty->assign('totals', $totals);

Open in new window


Please help me to get past this error.
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Nowhere in your code are you defining $smarty - you use it on line 200 of your source but that is the first time we see it - did you forget to include something in your script?
Avatar of sharingsunshine

ASKER

How do you do that?
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well, that did it.  I no longer have that error.  I have some new ones, though.  But I'll create another question for them.
Thanks for the help.
You are welcome.