dynamic links in layout

Hello everybody,

I’m working on a website with dynamic links, which can be adapted in a backend admin dashboard.

However I have a problem i’m retrieving my links with a beforeAction() in my CController (found in extensions) but my links are needed in the layout file so the layout file (/themes/mytheme/views/layouts/default.php). I come to the conclusion that I can’t do that because the layout file is rendered somewhere before i render my view files and before I begin my controller code.

Can anyone point me how I can still accomplish this?

Thank you!

Hello - the layout file is rendered after your controller and after your view

for example i set some metadata inside my view - or it is possible to change the layout inside the controller…

but for me it isn’t totally clear what you want to achieve…

you want to add links to your layout file from within the controller cause they are coming from the database? then it’s quite easy:

I added to my components/Controller.php:

public $menu=array();

and to my layout Columns2.php:

        <?php if($this->menu){ ?>

        <div class="span-5">

                <div id="sidebar">


                        $this->beginWidget('zii.widgets.CPortlet', array(



                        $this->widget('zii.widgets.CMenu', array(






                </div><!-- sidebar -->


        <?php } ?>

notice that the $this inside a layout refers to the $this of the controller… that’s why we have access to the $this->menu… so basically you should store the layout related stuff inside your controller

and finally i create the menu inside another controller which extends my components/Controller.php (but if you have a look inside the gii crud-creation you see it’s also possible to set the menu inside the view too - cause $this also refers to the controller inside the view)

class DefaultController extends Controller


        public function init()


                $this->menu = array(

                        array('label'=>'Categories', 'url'=>array('/category')),

                        array('label'=>'Entrytypes', 'url'=>array('/entrytype')),





i hope this is what you needed… :)

Thank! I don’t know why i didn’t see it yesterday evening, I just added a few if statements to eliminate problems