View previous topic :: View next topic |
Author |
Message |
cuppuccinu Smarty Rookie
Joined: 24 Jan 2012 Posts: 14
|
Posted: Tue Jan 24, 2012 10:20 am Post subject: Notice: Undefined index Error |
|
|
Hello,
i want to create a menu, so i have nav.tpl and nav.php
the content of nav.tpl is:
Code: | <div id="nav-container" class="span-18 last"><!--BEGIN NAV CONTAINER-->
<ul id="nav">
{foreach from=$nav key="abbreviation" item="title"}
<li><a href="?language={$abbreviation}">{$title}</</a></li>
{/foreach}
</ul>
</ul>
</div><!--END NAV CONTAINER-->
|
the content of the nav.php is:
Code: | <?php
include("libs/smarty.class.php");
$smarty = new Smarty;
$nav = array(
'en' => 'English',
'it' => 'Italian',
'de' => 'German',
'pt' => 'Portuguese'
);
$smarty->assign('nav', $nav);
$smarty->display('nav.tpl');
?> |
this is the message error that i get:
Notice: Undefined index: nav in D:\xampp\htdocs\****\templates_c
Thank you for help
Last edited by cuppuccinu on Tue Jan 24, 2012 8:13 pm; edited 1 time in total |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Jan 24, 2012 8:01 pm Post subject: |
|
|
This is strange.
From the error message I would assume that the Smarty variable $nav is not assigned.
But
Code: | $smarty->assign('nav', $nav);
|
says it is.
Are you sure that you don't have a typo somewhere? |
|
Back to top |
|
cuppuccinu Smarty Rookie
Joined: 24 Jan 2012 Posts: 14
|
Posted: Tue Jan 24, 2012 8:08 pm Post subject: |
|
|
i am sure and i am using the last version of smarty,can you help plz
thanks |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Tue Jan 24, 2012 8:28 pm Post subject: |
|
|
How does the compiled template look. Meaning, the file in templates_c?
Could you post that? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Jan 24, 2012 8:29 pm Post subject: |
|
|
Set
$smarty->debugging = true;
before the display() call and check if variable nav is really assigned. |
|
Back to top |
|
cuppuccinu Smarty Rookie
Joined: 24 Jan 2012 Posts: 14
|
Posted: Tue Jan 24, 2012 8:48 pm Post subject: |
|
|
this is the the line of the error in template_c
Code: | $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['loop'] = is_array($_loop=$_smarty_tpl->tpl_vars['FirstName']->value) ? count($_loop) : max(0, (int)$_loop); unset($_loop); |
and this the link to download a files that show the error
http://devxpress.net/~nabaha/smart.zip |
|
Back to top |
|
cuppuccinu Smarty Rookie
Joined: 24 Jan 2012 Posts: 14
|
Posted: Tue Jan 24, 2012 8:49 pm Post subject: |
|
|
no chance with $smarty->debugging = true; Mr U.Tews |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Jan 24, 2012 9:15 pm Post subject: |
|
|
With the files provided it's a completly different story.
Your file index.php does not assign a value for 'FirstName'.
If you expect unassigned variables you must disable E_NOTICE like
$smarty->error_reporting = E_ALL & ~E_NOTICE;
See also the note in the README file |
|
Back to top |
|
cuppuccinu Smarty Rookie
Joined: 24 Jan 2012 Posts: 14
|
Posted: Tue Jan 24, 2012 9:27 pm Post subject: |
|
|
Hello,
i used a code that i find in the demo of smarty and it works now,
Thank you very much |
|
Back to top |
|
cuppuccinu Smarty Rookie
Joined: 24 Jan 2012 Posts: 14
|
Posted: Tue Jan 24, 2012 10:16 pm Post subject: |
|
|
Hello, The problem presists,
when i launch the nav.php file it looks ok but when i lanch the index.php
i get the error .
nav is including in index using the code
Code: | {include file="nav.tpl"} |
Help plz |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Jan 24, 2012 11:06 pm Post subject: |
|
|
Does index.php assign something to variable nav?
$smarty->assign('nav',...); ?
I doubt it |
|
Back to top |
|
cuppuccinu Smarty Rookie
Joined: 24 Jan 2012 Posts: 14
|
Posted: Tue Jan 24, 2012 11:34 pm Post subject: |
|
|
no it does not, this is its content:
Code: | <?php
require('../libs/Smarty.class.php');
$smarty = new Smarty;
$smarty->display('index.tpl');
?> |
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Jan 24, 2012 11:42 pm Post subject: |
|
|
Again if you use in your template a variable which is in assigned in the PHP script you will get the undefined index notice unless you disable E_NOTICE by
$smarty->error_reporting = E_ALL & ~E_NOTICE;
This is not a bug..... |
|
Back to top |
|
cuppuccinu Smarty Rookie
Joined: 24 Jan 2012 Posts: 14
|
Posted: Tue Jan 24, 2012 11:49 pm Post subject: |
|
|
when i do $smarty->error_reporting = E_ALL & ~E_NOTICE; i get nothing no output |
|
Back to top |
|
|