|
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 |
Ceph Smarty Rookie
Joined: 25 Nov 2003 Posts: 24
|
Posted: Tue Aug 09, 2005 4:37 am Post subject: PHP5's MyObject::CONST syntax? |
|
|
Code: |
{if $page->GetClient()->status_type == Client::STATUS_DEMO}
|
syntax error: unidentified token '::STATUS_DEMO' (Smarty_Compiler.class.php, line 1384)
Also, $page->GetClient()->status_type compiles to:
elseif ($this->_tpl_vars['page']->GetClientWebsite() - > status_type
I know Smarty doesn't officially support PHP5, but any idea how I could fix either of those? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Aug 09, 2005 4:46 am Post subject: |
|
|
Perhaps use a config file. Since config files support custom resources you might want to write one that introspects your class instead of duplicating the constant definitions in both your class and a real config file. That way you should be able to do something like:
{config_load file="ClassConstants:Client"}
{if $foo == #STATUS_DEMO#}
I haven't actually tried (or needed) such a thing but it should work well enough.
Perhaps a little bit simpler, you can extend your custom Smarty class and add a method that introspects a given class and assigns it to a standard array that you can define:
$smarty->assignClassConstants('Client');
---
{if $foo == $const.Client.STATUS_DEMO}
or something along those lines.
As for page->GetClient()->status_type, please search the forum for 'derefrencing'. |
|
Back to top |
|
Ceph Smarty Rookie
Joined: 25 Nov 2003 Posts: 24
|
Posted: Tue Aug 09, 2005 4:59 am Post subject: |
|
|
The constants issue isn't a biggie, as you said. I did write a simple converter method in my derived Smarty object to convert all class constants to real constants.
However, Smarty breaking the object code isn't very nice.
I can only resort to:
{assign var="client" value=$page->GetClient()}
{if $client->status_type ...
which works for now I guess. Will a "5" version be released? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Aug 09, 2005 5:49 am Post subject: |
|
|
Well... you may think of it of breaking code or you can think of it as supporting PHP4 style objects which is what Smarty 2.x is designed to do. My guess is that Smarty 3.x will address the issue of PHP5 style objects. |
|
Back to top |
|
Ceph Smarty Rookie
Joined: 25 Nov 2003 Posts: 24
|
Posted: Tue Aug 09, 2005 12:46 pm Post subject: |
|
|
In case anyone else needs to use class constants in PHP5/Smarty 2 series:
Code: |
{if $client->GetStatusCode() == constant("Client::STATUS_SUSPENDED")}
|
works fine, as does:
Code: |
{"Client::STATUS_SUSPENDED"|constant}
|
|
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Aug 09, 2005 3:36 pm Post subject: |
|
|
nice one, ceph! |
|
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
|