I might be wrong.But is it possible to send array from controller to layout ->header.php in YII as controller send array data to view file?
public $variable;
public function actionView(){
$model = blabla::model()->findbypk($id);
$this->variable = $model->name;
$this->render('view', array('model'=>$model));
}
and then, you can use $this->variable in your layout
I had the same problem as you. Needed to pass to my layout a variable defining which items would be rendered in a menu.
In my case I decided to create a Widget.
I imported in the configuration file:
'import'=>array(
'application.widgets.Menu'
)
the Menu class:
class Menu extends CWidget{
public function init(){}
public function run(){
$rs = Yii::db()->menus->find(array('profile' => Yii::app()->user->profile));
$this->render('menu', array(
'menus' => $rs['menus']
));
}
}
and the menu view:
foreach($menus as $key=>$menu): ?>
<li>
<a href="<?php echo $menu['url']; ?>"><?php echo $menu['name']; ?></a>
</li>
<?php endforeach; ?>
In the layout I imported the widget:
<ul class="menus">
$this->widget('application.widgets.Menu');
</ul>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With