CakePHP and Smarty(ies)

Joe Topjian has written a tutorial about using Smarty, a template engine, with CakePHP. If you ever wanted to use Smarty with CakePHP, go for it! But be warned, there are some restrictions (e.g. no access to the html helper).

@Yoeri: In my opinion there is no reason to use a template engine on top of CakePHP. But there are people out there who like something like smarty. So if you want to use smarty with CakePHP, you can do it, but personally I don’t recommend it.

masterjail ment the smarty->fetch which will return the compiled template html code (the same code that would end up in your browser). He wants the output in a variable instead of sending it to the browser.

Smarty is a lot better than writing php templates because it reduces the template code (which is a lot better if you are working with a web designer).

If only PHP had a Clay-style templating engine (Facelets is likely going to be Clay-like).

And for all those who say “smarty is slow” — you are absolutely wrong. Smarty compiles to native php so it is just as fast as writing an actual php file but Smarty is cleaner and usually faster to develop with.

Aren’t smarty templates ‘safer’ than direct PHP? Building a user configurable system that allows site maintainers to upload templates without worrying about rouge code with system calls and embedded database commands.

It would seem that this Smarty or an advanced template system would be a valuable addition to applications with user configurable views.

from controller you assing $posts to smarty ie. $tpl->assign(“posts”, $this->requestAction(‘posts/index’);

in the .tpl file:
{section name=iloop loop=$posts}
{$posts[iloop][title]}
{/section}
or there abouts, it’s been again a month or so last time i used smarty (not my choice not to use!)

As for Smarty benefits:
– It compiles the code
– Caching engine (huge difference in speed)
– Simpler templating
– Less code on templates (less clutter, no spaghetti)
– Complete disseparation of layout from other parts of the system, and i mean COMPLETE. Which means once again: SIMPLER :)

@Rani: Hm, difficult to say as I don’t have any experience with Smarty… The “cake way” is to use “normal” PHP in the views, though there are some people using Smarty, see the bakery and/or the cakephp google group.

An early decision you must make is how you want to access to the stock market.
If you want to be a passive trader and leave the management to an industry professional, mutual funds are good options that provide automatic portfolio diversficiation.
If you are more of a do-it-yourselfer, then picking and trading your own
stocks is possible too. Splitting your investment between both is a choice that some
do as well.
__________________________________________________________________________