|
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 |
c77m Smarty n00b
Joined: 09 Jul 2003 Posts: 2
|
Posted: Wed Jul 09, 2003 12:25 pm Post subject: Problem with nested objects |
|
|
I am trying to implement some pages that make use of nested objects, ie:
Code: |
class Obj1 () {
function Obj1() {
$this->attribute1 = new Obj2();
}
function obj2() {
return $this->attribute1();
}
}
$obj1 = new Obj1();
$smarty->assign_by_ref("obj1");
|
I am having trouble referring to the nested object in my templates. Addressing attributes DOES work:
Code: | {$obj1->attribute1->attribute2} |
Addressing object functions does not:
Code: | {$obj1->obj2()->attribute2} |
I can't seem to find any examples. Can someone tell me what I am doing wrong? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jul 09, 2003 4:02 pm Post subject: |
|
|
Hi.
Quote: | Addressing object functions does not:
Code:
{$obj1->obj2()->attribute2} |
Dereferencing functions like this also does not work in PHP4, by-the-way, which is *probably* why it does not work in Smarty.
Last edited by boots on Wed Jul 09, 2003 9:33 pm; edited 1 time in total |
|
Back to top |
|
c77m Smarty n00b
Joined: 09 Jul 2003 Posts: 2
|
Posted: Wed Jul 09, 2003 8:17 pm Post subject: |
|
|
Well howabout that... that could be the problem indeed. I ran into this while I was trying to clean up my code (by addressing object funtions instead of properties.) Time for a new approach.
thanks again.. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jul 09, 2003 9:36 pm Post subject: |
|
|
I forgot to mention that as per PHP4, you can still do an intermediate assignment to mimic the behaviour you desire--its just not as clean and possibly not as fast (especially if you don't pass by reference):
{assign var=temp value=$obj1->obj2()}
{$test->attribute2} |
|
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
|