Tuesday, 17 September 2013

Undefined index error is thrown although the array clearly has an index

Undefined index error is thrown although the array clearly has an index

I am getting an undefined index error although that I am certain that my
array has values any idea why ?
PHP:
$categories = array();
foreach ($arr as $h) {
$categories[] = trim($h['category']);
}
$uniquecategories = array_unique($categories);
sort($uniquecategories);
print_r ($uniquecategories);
$smarty->assign('uniquecategories',$uniquecategories);
$list['items']=$smarty->fetch('../templates/popupMyItems.tpl',$h);
print_r ($list['items']);
OUTPUT OF print_r ($uniquecategories);
Array ( [0] => CAT1 [1] => CAT2 [2] => CAT3 [3] => CAT4 [4] => CATOTHER
[5] => Everything Else
TPL:
{foreach
from=$uniquecategories item=category name=cat}
{if $smarty.foreach.cat.first} {include
file="../templates/list-myItems.tpl"
category="{$category|replace:' ':''}" active="true"}
{else} {include
file="list-myItems.tpl" category="{$category|replace:' ':''}"
active="false"} {/if}
{/foreach}
ERROR THROWN:
<b>Notice</b>: Undefined index: uniquecategories in <b>C:\Program Files
(x86)\Apache Software
Foundation\Apache2.2\htdocs\ex\main\actions\templates_c\07c3452c9173e47b89ab427877861e26b839928c.file.popupMyItems.tpl.php</b>
on line <b>40</b><br />
<br />
NOTE: I shouldn't have to pass $h on the smarty->fetch
$list['items']=$smarty->fetch('../templates/popupMyItems.tpl',$h); but if
I dont pass a var the whole think breaks.
So If I do
$list['items']=$smarty->fetch('../templates/popupMyItems.tpl');
error</b>: Uncaught exception 'SmartyException' with message 'Unable to
load template file 'list-myItems.tpl' in '../templates/popupMyItems.tpl''
in C:\Program Files (x86)\Apache Software
Foundation\Apache2.2\htdocs\ex\libs\sysplugins\smarty_internal_templatebase.php:127
Stack trace: #0 C:\Program Files (x86)\Apache Software
Foundation\Apache2.2\htdocs\ex\libs\sysplugins\smarty_internal_template.php(286):
Smarty_Internal_TemplateBase-&gt;fetch(NULL, NULL, NULL, NULL, false,
false, true) #1 C:\Program Files (x86)\Apache Software
Foundation\Apache2.2\htdocs\ex\main\actions\templates_c

No comments:

Post a Comment