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?
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')),
);
parent::init();
}
}