Using Yii with Smarty

I read an article about this and downloaded the CSmartyViewRenderer class but according to the article I’d have to edit the framework files directly to override the default view renderer. Is there a more elegant way to do this?

Also I’m not sure where I’d include the Smarty classes…

(still getting the hang on Yii!)

Thanks!!

Alex

No, you don’t need (and shouldn’t) modify the framework file. You just need to configure in the app config with

‘viewRender’=>array(‘class’=>‘path.to.CSmartyViewRenderer’)

BTW, where did you read the article, and where did you get CSmartyViewRenderer?

Thanks for the reply, can you please shed some more light on this?

I included the CSmartyViewRenderer class in my project’s extensions folder and added the line in the app config file.

I’m not sure where exactly I should specify the path to include the Smarty classes though? (/usr/share/php/Smarty)

I tried doing it manually using require_once but I’m pretty sure there is a more elegant way although I’ve had no luck using Yii::import().

By the way, this is the link.

Its in spanish and it requires messing around with the framework files if I understood it correctly so I couldn’t get it to work.

Thanks!

A mistake in that article is that it attempts to modify YiiBase.php, which it shouldn’t.

You just need to configure the app config as:




'components'=>array(

    'viewRenderer'=>array(

         'class'=>'application.extensions.smarty.CSmartyViewRenderer',

    ),

),



thanks, ill give it a shot!

how can i load the smarty classes without doing a require_once in the CSmartyViewRenderer? is there any way I can add it to the autoloader ?

thanks!

You need to explicitly include smarty classes if they don’t follow Yii’s convention (class name is the file name).

The difference resides in the extension, Yii uses "Classname.php" and Smarty uses "Classname.class.php" … is there a way to specify a different extension (spl_autoload_extensions?)

Thanks for your patience and feedback Qiang! :)

If and when I manage to get a satisfactory set up working with Smarty I’ll definitely write it up so others can learn from my experience!

I would suggest not to try autoloading smarty classes because it doesn’t worth the effort (it doesn’t improve performance anyway). If you really want to do so, you can write an autoload function and register it using spl_autoload_extensions BEFORE you include yii.php.

I’d recommend not to use any ViewRenderers and stick with php-based templates.

A rule of thumb not to make things more complex without a real need. Do you

really need this?

Also, read this.

waylex, I couldn’t agree more with you!

However, I’m considering rewriting our application to use Yii (custom mvc at the moment) and since its already done with Smarty and all the templates and view stuff is already done, for now it really makes no sense to complicate things even more! I hate Smarty but the rest of our team likes it…

Hi everybody,

I was reading the artycle about Smarty into Yii, and I try to download de extention, but the download link no longer exists. I try to SVN but there is nothing yet. Some one know how can I download it?

Sorry for my english(I’m Brazilian).

I found what I was looking. The download link: