View previous topic :: View next topic |
Author |
Message |
cuppuccinu Smarty Rookie
Joined: 24 Jan 2012 Posts: 14
|
Posted: Wed Jan 25, 2012 12:55 am Post subject: array error in include |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jan 25, 2012 3:11 pm Post subject: |
|
|
It looks like there are some things not assigned to the template that are expected. Namely, the $items object. |
|
Back to top |
|
cuppuccinu Smarty Rookie
Joined: 24 Jan 2012 Posts: 14
|
Posted: Wed Jan 25, 2012 6:36 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jan 25, 2012 7:17 pm Post subject: |
|
|
when you run test.php, nothing gets assigned to smarty, so the variables the templates are expecting will throw notices. ??? |
|
Back to top |
|
cuppuccinu Smarty Rookie
Joined: 24 Jan 2012 Posts: 14
|
Posted: Wed Jan 25, 2012 7:29 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jan 25, 2012 7:35 pm Post subject: |
|
|
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 |
|
cuppuccinu Smarty Rookie
Joined: 24 Jan 2012 Posts: 14
|
Posted: Wed Jan 25, 2012 7:39 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jan 25, 2012 7:55 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jan 25, 2012 7:58 pm Post subject: |
|
|
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 |
|
cuppuccinu Smarty Rookie
Joined: 24 Jan 2012 Posts: 14
|
Posted: Wed Jan 25, 2012 8:04 pm Post subject: |
|
|
how can i solve this plz? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jan 25, 2012 8:27 pm Post subject: |
|
|
what are you trying to solve? the issue has been explained. |
|
Back to top |
|
cuppuccinu Smarty Rookie
Joined: 24 Jan 2012 Posts: 14
|
Posted: Wed Jan 25, 2012 8:28 pm Post subject: |
|
|
thank you very much Mohrt,
your solution wroks fine |
|
Back to top |
|
|