Re: [SMARTY] Object access

From: Date: Thu, 06 Mar 2003 22:37:18 +0000
Subject: Re: [SMARTY] Object access
References: 1 2 3 4  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-8464@lists.php.net to get a copy of this message
That is incorrect. Detailed example: <?php $smarty = new Smarty; $obj = new Object; //$obj->method would return a php associative array $smarty->assign('obj', $obj); $smarty->display('index.tpl'); ?> index.tpl: {$obj->method assign="arr"} {foreach item="item" from=$arr} {$item}<br/> {/foreach} However $arr never gets defined so nothing is printed. Thanks, Tom messju mohr wrote:
On Fri, Mar 07, 2003 at 09:12:57AM +1100, Tom Rochester wrote:
messju, I understand this, '$obj->method outputs an associative array' should have read '$obj->method returns an associative array' But my example is not working it is not being assigned to $arr Thanks, Tom messju mohr wrote:
Hello, On Thu, Mar 06, 2003 at 03:43:32PM +1100, Tom Rochester wrote:
     
How does one assign to output of an objects method? The manual states that {$obj->method p1="" assign="output"} should work
       
rrr, of course it should read {obj->method p1=...} not {$obj->method p1=...} is that the problem?
but it doesn't. Also tried {$obj->method() assign="output"} but this simple outputs the array (ie "Array" is this getting closer?) Specific example: $obj->method outputs an associative array. index.tpl : {$obj->method p1="" assign="arr"} {foreach item="item" from=$arr} {$item}<br/> {/foreach} How can I achieve this functionality? Thanks,
       
not the output of the method is assigned, but the return-value. also the return-value is printed to the page if no "assign=" is given. so your methods should return their output, not echo it. then the output can be assigned optionally. HTH messju
     
Tom
       
     


« previous php.smarty.general (#8464) next »