Re: [SMARTY] Developing miscellaneous classes
| From: | Nick Charsley | Date: | Wed, 14 Aug 2002 08:14:15 +0000 |
| Subject: | Re: [SMARTY] Developing miscellaneous classes | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5692@lists.php.net to get a copy of this message | ||
Not sure if this is the best way to do it, but I had a similar problem and
this is how I handled it....
Added a function after my class to call the member functions of the class,
registered that with smarty and then called it in the template i.e
class clsTeam
{
..
function Name()
{
...
}
..
}
function Smarty_Team($params)
{
// Called from smarty so
extract($params);
echo $class->$property();
// this works with echo but not with return
}
$smarty->register_function('Team','Smarty_Team');
so creating it as
$class=new clsTeam;
then in the template
{Team class=$class property="Name"}
and out comes the results of the function. Although I've not needed to I
think this could be extended to pass parameters through to the class
function.
If anyone has a better way I'd love to see it.
Nick (c)
----- Original Message -----
From: "Eskil Kvalnes" <eskil@uten.net>
To: "Smarty Mailing List" <smarty-general@lists.php.net>
Sent: Wednesday, August 14, 2002 8:47 AM
Subject: [SMARTY] Developing miscellaneous classes
> Hey,
>
> I have a few classes on my smarty powered site..
> And I'm wondering how I modify my classes so that
> they also work with smarty?
>
> Right now, I just work around it and it ain't looking good.
> For instance, if I have:
>
> $class = new class();
> $class->printToScreen();
>
> that works, but when I use smarty I cheat and do this:
>
> $class = new class();
> $_SMARTY->assign("PRINTTOSCREEN", $class->printToScreen());
>
> At first, (when I was using echo in the printToScreen() function, it just
> placed
> the text within echo before the templates were parsed. Then I changed it
to
> 'return' and it got placed properly.
>
> Now I've come to another problem.. One obviously cannot use return
multiple
> times
> within one function..
>
> So if anyone can give me some guidelines on how I make custom classes work
> with smarty
> that would be great :-)
>
> ---------------
> Sincerely,
> Eskil Kvalnes
> eskil@uten.net
>
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>