View previous topic :: View next topic |
Author |
Message |
gajdaw Smarty n00b
Joined: 15 Apr 2008 Posts: 2
|
Posted: Tue Apr 15, 2008 6:47 am Post subject: Smarty/Propel and multiple method calls in the template |
|
|
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 |
|
shannera Administrator
Joined: 13 Feb 2006 Posts: 802 Location: Edertal, Germany
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Sep 08, 2008 4:25 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Sep 08, 2008 4:42 pm Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Sep 08, 2008 5:00 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Sep 08, 2008 6:56 pm Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Sep 08, 2008 7:12 pm Post subject: |
|
|
Monte the work around would be to evaluate the chain step by step. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Sep 08, 2008 10:44 pm Post subject: |
|
|
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 |
|
gajdaw Smarty n00b
Joined: 15 Apr 2008 Posts: 2
|
Posted: Tue Sep 09, 2008 9:51 am Post subject: |
|
|
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
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 |
|
|