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

Smarty/Propel and multiple method calls in the template

 
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 -> Smarty Development
View previous topic :: View next topic  
Author Message
gajdaw
Smarty n00b


Joined: 15 Apr 2008
Posts: 2

PostPosted: Tue Apr 15, 2008 6:47 am    Post subject: Smarty/Propel and multiple method calls in the template Reply with quote

Hello everyone,

I use Smarty + Propel and very often get the problem of accessing properties returned by methods.

Example

1. Database consists of three tables: Author, Book, BookHasAuthor

2. PHP/Propel code to retrieve all the books by first author:

$a = AuthorPeer::retrieveByPK(1);
$info = $a->getAuthorHasBookJoinBook(new Criteria);
$s->assign('info', $info);

3. The template:

{$info[0]->getAuthor()->getFirstName()}

This code will produce an error message.




To solve this problem I modify regular expressions that parse the template. If the original line #155 of Smarty_compiler.class.php:



$this->_obj_ext_regexp = '\->(?:\$?' . $this->_dvar_guts_regexp . ')';



is modified to:


$this->_obj_ext_regexp = '\->(?:\$?' . $this->_dvar_guts_regexp . '(?:\(\))?)';



then multiple method calls are allowed within the template.


Does anyone know better solution?

Will Smarty 3.0 allow multiple method calls?


thx in advance,
gajdaw
Back to top
View user's profile Send private message
shannera
Administrator


Joined: 13 Feb 2006
Posts: 802
Location: Edertal, Germany

PostPosted: Mon Sep 08, 2008 1:14 pm    Post subject: Reply with quote

As you can see in the thread http://www.phpinsider.com/smarty-forum/viewtopic.php?t=4989, there aren't many fixed plans for Smarty 3.0, and no development startet, so I doubt someone can say if this feature will be supported.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Mon Sep 08, 2008 4:25 pm    Post subject: Reply with quote

The problem of method chaining was discussed already several times. PHP4 does not support this. Your modification will only work with PHP5. It was not implemented in Smarty because of its requirement to be compatible with PHP4.

[/code]
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Sep 08, 2008 4:42 pm    Post subject: Reply with quote

I'm not against adding this patch to Smarty 2.x, so long as it is understood that method chaining on PHP4 will come up with a syntax error. When PHP5 was new, this patch wasn't so appealing because of the large PHP4 user base. PHP4 is getting further into the past now. This can be an undocumented feature, for those that wish to use it.
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


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

PostPosted: Mon Sep 08, 2008 5:00 pm    Post subject: Reply with quote

Monte what's about introducing a configuration parameter like php5 = true and implement for PHP4 a workaround. If you like I could look into it.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Sep 08, 2008 6:56 pm    Post subject: Reply with quote

The only work around would be to display an error, as PHP4 will not handle method chaining. You can also detect the PHP version without a setting.
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


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

PostPosted: Mon Sep 08, 2008 7:12 pm    Post subject: Reply with quote

Monte the work around would be to evaluate the chain step by step.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Mon Sep 08, 2008 10:44 pm    Post subject: Reply with quote

An updated version of Smarty_Compiler.class.php is now in the SVN.

It allows method chaining in both PHP4 and PHP5.
Back to top
View user's profile Send private message
gajdaw
Smarty n00b


Joined: 15 Apr 2008
Posts: 2

PostPosted: Tue Sep 09, 2008 9:51 am    Post subject: Reply with quote

U.Tews wrote:
An updated version of Smarty_Compiler.class.php is now in the SVN.

It allows method chaining in both PHP4 and PHP5.


Thank you for your interest and work Smile

I think method chaining is indispensable when working with Propel/Smarty.

I hope other Smarty users will find it useful.

Thank you once again,
gajdaw
Back to top
View user's profile Send private message
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 -> Smarty Development 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