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

array error in include

 
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: Wed Jan 25, 2012 12:55 am    Post subject: array error in include Reply with quote

Hello i have a menu file that output a menu (menu.php and menu.tpl)
i included it in a header (header.php and header.tpl) like this
Code:
{include file="menu.tpl"}


when launch the menu.php in the browser it give me the menu,
but when launch header.php

it give an error in the place the menu and this the error:

Code:
Notice: Undefined index: items in D:\xampp\htdocs\smart\templates_c\85192c6e9f55456bef8cf932502504a0684ee09b.file.menu.tpl.php on line 33

Notice: Trying to get property of non-object in D:\xampp\htdocs\smart\templates_c\85192c6e9f55456bef8cf932502504a0684ee09b.file.menu.tpl.php on line 33
Back to top
View user's profile Send private message Send e-mail
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Jan 25, 2012 3:11 pm    Post subject: Reply with quote

It looks like there are some things not assigned to the template that are expected. Namely, the $items object.
Back to top
View user's profile Send private message Visit poster's website
cuppuccinu
Smarty Rookie


Joined: 24 Jan 2012
Posts: 14

PostPosted: Wed Jan 25, 2012 6:36 pm    Post subject: Reply with quote

This is a demo of the probelem:
http://devxpress.net/~nabaha/htdocs.zip

the index file works fine ,
buy after including it in test file
the arrays return an error

can you help plz
Back to top
View user's profile Send private message Send e-mail
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Jan 25, 2012 7:17 pm    Post subject: Reply with quote

when you run test.php, nothing gets assigned to smarty, so the variables the templates are expecting will throw notices. ???
Back to top
View user's profile Send private message Visit poster's website
cuppuccinu
Smarty Rookie


Joined: 24 Jan 2012
Posts: 14

PostPosted: Wed Jan 25, 2012 7:29 pm    Post subject: Reply with quote

thank your for your replay

try to see http://localhost/demo/index.php
and http://localhost/demo/test.php

index is in icluded in test
using
Code:
{include file='index.tpl'}


test shoud return the same content as index
it returns all things but an error in the plac of arrays
Back to top
View user's profile Send private message Send e-mail
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Jan 25, 2012 7:35 pm    Post subject: Reply with quote

no it shouldn't. compare index.php to test.php. you will see index.php assigns the data required in the templates. test.php does not, thus the errors.
Back to top
View user's profile Send private message Visit poster's website
cuppuccinu
Smarty Rookie


Joined: 24 Jan 2012
Posts: 14

PostPosted: Wed Jan 25, 2012 7:39 pm    Post subject: Reply with quote

index.php have it tpl file.
test.php too
what i want is to include index in test
i have the data in index so why i need to write the too in test?
Back to top
View user's profile Send private message Send e-mail
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Jan 25, 2012 7:55 pm    Post subject: Reply with quote

if the browser uses test.php to draw the page, index.php is never included, thus the data is never assigned. see here:

example #1:
browser -> index.php (tpl data assigned) -> display index.tpl

example #2:
browser -> test.php -> display test.tpl -> include index.tpl

nowhere in example #2 is the data assigned.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Jan 25, 2012 7:58 pm    Post subject: Reply with quote

If you want the data assigned in BOTH index.php and test.php, you need to move that assignment code to a place that can be utilized by both. This is easily solved by a PHP programmer.
Back to top
View user's profile Send private message Visit poster's website
cuppuccinu
Smarty Rookie


Joined: 24 Jan 2012
Posts: 14

PostPosted: Wed Jan 25, 2012 8:04 pm    Post subject: Reply with quote

how can i solve this plz?
Back to top
View user's profile Send private message Send e-mail
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Jan 25, 2012 8:27 pm    Post subject: Reply with quote

what are you trying to solve? the issue has been explained.
Back to top
View user's profile Send private message Visit poster's website
cuppuccinu
Smarty Rookie


Joined: 24 Jan 2012
Posts: 14

PostPosted: Wed Jan 25, 2012 8:28 pm    Post subject: Reply with quote

thank you very much Mohrt,

your solution wroks fine Smile
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