Re: [SMARTY] Object access
| From: | messju mohr | Date: | Thu, 06 Mar 2003 22:51:37 +0000 |
| Subject: | Re: [SMARTY] Object access | ||
| References: | 1 2 3 4 5 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-8465@lists.php.net to get a copy of this message | ||
On Fri, Mar 07, 2003 at 09:37:18AM +1100, Tom Rochester wrote:
> 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}
i think you mix
{foobar->meth1 p1="foo" p2=$bar} // for registered objects
vs.
{$myobj->meth1("foo",$bar)} // for assigned objects
(notation from http://smarty.php.net/manual/en/advanced.features.php)
assign="output" only works for registered, but not for assigned objects.
> 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
> >>>>
> >>>>
> >>>>
> >>>>
> >>>
> >>>
> >>>
> >
> >
> >
>
>
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
Torx-Schrauben: Hände-Weg-Schrauben
nach Marc Habers Kollegen