AR information in header div

The layout structure of the site I am currently working on is based on the default Yii layout with some minor modifications where the basic structure of main.php is




   <body>

     <div class="container">

       <div id="header" />

       <div id="mainmenu" />

       

       <?php echo $content; ?>


       <div id="footer" />

     </div>

   </body>



Is there a way to access the view’s AR information from main.php and use it to display some information in the header div without having to move the header from main.php into each view?

Thanks!

Look at the way the standard ‘column2’ layout uses the controller to access the menu items. I think you will find your solution there =)

Your view can populate properties (or properties belonging to attached behaviors) to your controller, which can be accessed via the layout file or widgets within the layout file.

Thanks for your reply, but I’m not sure I understand. Are you saying the only way to do it is to create a widget?

You need to add additional properties to a base controller (components/Controller.php), e.g.:




class Controller extends CController

{

    public $title;

    // ...



Assign the title value inside a particular controller with $this->title = $model->name and use it inside a layout file:




<div><?php echo $this->title; ?></div>



That’s a true way ;)

That’s perfect! Thanks!