Re: Re[2]: Passing in objects by reference (Pull approach w/ Smarty)
| From: | Andrei Zmievski | Date: | Fri, 06 Jul 2001 15:38:31 +0000 |
| Subject: | Re: Re[2]: Passing in objects by reference (Pull approach w/ Smarty) | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-1126@lists.php.net to get a copy of this message | ||
On Thu, 05 Jul 2001, Oleg Rekutin wrote:
> Would it then be possible for Smarty to support calling object
> methods?
Probably not via a special syntax or anything like that. I'm afraid it's
going to grow teeth and evolve into its own programming language. Then
Rasmus will come after me with a shotgun.
> If the ticker retrieval logic is moved out into one shared class, then
> unlimited templates can take advantage of this.
>
> With the {php} section, the example would then change to:
>
> {php}
>
> $tickers->fetch("YHOO", $ticker_name, $ticker_price);
>
> // assign template variables
> $this->assign("ticker_name",$ticker_name);
> $this->assign("ticker_price",$ticker_price);
>
> {/php}
>
> Stock Name: {$ticker_name} Stock Price: {$ticker_price}
>
> (Well, it doesn't have to be $tickers->fetch, it can be a simple API
> using fetch_ticker.) But wouldn't it be nicer if it were simply
> something like:
>
> {$tickers->fetch("YHOO")}
> Stock Name: {$ticker_name} Stock Price: {$ticker_price}
>
> (Tickers::fetch, in this case, assigns template variables using the
> Smarty API).
I think you can already do this. If you assign $tickers to a template
and it's an object you can do:
{php}
$tickers->fetch("YHOO");
{/php}
and if tickers::fetch() assigns template vars via API, they should be
available to the template.
-Andrei
Some people try to achieve immortality through their work, others
through their children. I hope to achieve immortality by not dying.
-- Woody Allen