Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Notice: Undefined index Error

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
cuppuccinu
Smarty Rookie


Joined: 24 Jan 2012
Posts: 14

PostPosted: Tue Jan 24, 2012 10:20 am    Post subject: Notice: Undefined index Error Reply with quote

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
View user's profile Send private message Send e-mail
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Jan 24, 2012 8:01 pm    Post subject: Reply with quote

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
View user's profile Send private message
cuppuccinu
Smarty Rookie


Joined: 24 Jan 2012
Posts: 14

PostPosted: Tue Jan 24, 2012 8:08 pm    Post subject: Reply with quote

i am sure and i am using the last version of smarty,can you help plz
thanks
Back to top
View user's profile Send private message Send e-mail
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Tue Jan 24, 2012 8:28 pm    Post subject: Reply with quote

How does the compiled template look. Meaning, the file in templates_c?

Could you post that?
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Jan 24, 2012 8:29 pm    Post subject: Reply with quote

Set

$smarty->debugging = true;

before the display() call and check if variable nav is really assigned.
Back to top
View user's profile Send private message
cuppuccinu
Smarty Rookie


Joined: 24 Jan 2012
Posts: 14

PostPosted: Tue Jan 24, 2012 8:48 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
cuppuccinu
Smarty Rookie


Joined: 24 Jan 2012
Posts: 14

PostPosted: Tue Jan 24, 2012 8:49 pm    Post subject: Reply with quote

no chance with $smarty->debugging = true; Mr U.Tews
Back to top
View user's profile Send private message Send e-mail
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Jan 24, 2012 9:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
cuppuccinu
Smarty Rookie


Joined: 24 Jan 2012
Posts: 14

PostPosted: Tue Jan 24, 2012 9:27 pm    Post subject: Reply with quote

Hello,
i used a code that i find in the demo of smarty and it works now,
Thank you very much
Back to top
View user's profile Send private message Send e-mail
cuppuccinu
Smarty Rookie


Joined: 24 Jan 2012
Posts: 14

PostPosted: Tue Jan 24, 2012 10:16 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Jan 24, 2012 11:06 pm    Post subject: Reply with quote

Does index.php assign something to variable nav?

$smarty->assign('nav',...); ?

I doubt it
Back to top
View user's profile Send private message
cuppuccinu
Smarty Rookie


Joined: 24 Jan 2012
Posts: 14

PostPosted: Tue Jan 24, 2012 11:34 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Jan 24, 2012 11:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
cuppuccinu
Smarty Rookie


Joined: 24 Jan 2012
Posts: 14

PostPosted: Tue Jan 24, 2012 11:49 pm    Post subject: Reply with quote

when i do $smarty->error_reporting = E_ALL & ~E_NOTICE; i get nothing no output
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP