How automatically pass variable to view template?

Hello,

is it possible automatically pass some particular variable(s) to View template in base Controller? I’m annoyed always doing this in my templates:




<?php $formater = Yii::app()->localeFormater; ?>


...


<h3><?= $post->title ?></h3>

<span class"date"><?= $formater->date($post->created) ?></span>


...



Either I fetch localeFormater in template by static call to CWebApplication, or I can pass it in Controller:




public function actionFoo()

{

    ...


    $this->render('foo', array(

        'post' => $post,

        'formater' => Yii::app()->localeFormater,

    ));

}



I don’t like none of the above soutions. It would be nice to be able pass some common variables to template in univesal parent (Controller extends CController) of all Controllers, thus not altering code in actions/templates. Is this possible in Yii?

You can define controller public property(variable), and it will be visible in all views, that this controller render.

For example:




class ContactController extends Controller

{

    public $breadcrumb = "Contacts";

...

...

...