|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
shuther Smarty Rookie
Joined: 04 Jan 2004 Posts: 13
|
Posted: Sun Jan 04, 2004 9:04 pm Post subject: issue with objets registered through a template |
|
|
I think I found a bug(I think), let's see. (found in the last version, but existed in 2.5)
I have a file a.tpl with:
Code: | {include_php file="a.php" once=true }
{Preferences->getValue p1="show_number_events_month" assign="SeeNumberEvents"} |
Now, in the a.php file, I have:
Code: | global $smarty, $prefs;
//Traditionnal way
$smarty->register_object('Preferences', $prefs, null, false); |
It won't work:
Quote: | Fatal error: Smarty error: registered 'HordePreferences' is not an object in c:\devl\smarty\libs\Smarty.class.php on line 1885 |
But if I do this now in a.tpl
Code: | {include_php file="a.php" once=true }
{include file="b.tpl"} |
And in b.tpl, I have
Code: | {Preferences->getValue p1="show_number_events_month" assign="SeeNumberEvents"} |
It will work. I removed the templates_c directory during each try, because the behavior is weird (if I do the correct thing once, -exemple 2-, and go to the exemple 1, It will work until I clean the templates_c directory).
I was unable to track the issue; it seems that Smarty is checking the method name when it parses the file, before include the php file.
Hope that helps,
Steve |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sun Jan 04, 2004 9:46 pm Post subject: |
|
|
Registered objects are checked at compile-time. You cannot dynamically include an object-registration. |
|
Back to top |
|
shuther Smarty Rookie
Joined: 04 Jan 2004 Posts: 13
|
Posted: Thu Jan 08, 2004 3:55 pm Post subject: So |
|
|
That is why I think it is a bug. There is a turnaroung, but it is not very clean. I tried to register a empty object in the main php file, but that doesn't help, because smarty is checking the method name. Maybe a flag to make this check should exist? Or before doing it, every include_php should be run?
What do you think? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Jan 08, 2004 4:38 pm Post subject: |
|
|
it's not a bug.
the object is *registered* like a plugin is *registered*. you cannot compile a template and register used plugins with {include_php} while compiling the template, either. what you do is plain bad and a misuse of the concept of registered_objects.
the fact that it works for you sometimes (if you compile the templates in the right order) is a side-effect that you cannot rely on.
it seems you have to use assigned objects for what you want (with all their limitations) or reconsider your (application-)design. |
|
Back to top |
|
shuther Smarty Rookie
Joined: 04 Jan 2004 Posts: 13
|
Posted: Tue Jan 13, 2004 2:49 pm Post subject: Feature request or bug |
|
|
Ok, for me it is a bug, I am going to explain why:
When we can the a.tpl file
Code: | {include_php file="a.php" once=true }
{include file="b.tpl"}
|
and the b.tpl file
Code: |
{Preferences->getValue p1="show_number_events_month" assign="SeeNumberEvents"} |
It is working perfectly.
If it doesn't work, it is because Smarty checks that the object and the method really exist at compile time. Something that we should (or could) skip in production; or we could do the check after the include_php.
Why is it required?
In the application design I am using, it is working like this:
Each file.php contains more or less:
Code: | $smarty->display('index.tpl') |
and index.tpl includes a lot of .tpl and .php file that will do what is required, based on the page seen, and the different parameters.
At this time, everything is working properly, but I need to use the workaround provided above (2 .tpl) instead of just 1, because Smarty is doing a useless check. This issue doesn't happen with assign or assign_by_ref.
So if it is not a bug, would it be possible to take it as a feature request?
Thank you |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Jan 13, 2004 3:21 pm Post subject: Re: Feature request or bug |
|
|
shuther wrote: | If it doesn't work, it is because Smarty checks that the object and the method really exist at compile time. |
correct.
Quote: | Something that we should (or could) skip in production; |
wrong. smarty needs to know *at compile time* if {foo->bar} calls a method or accesses an object's property.
Quote: | or we could do the check after the include_php. |
wrong. this would intermix compilation and display of a single tpl-file. that's a really bad idea. |
|
Back to top |
|
|
|
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
|