Do not resurrect dead mail, but this is what I do (which, in my opinion, is a little cleaner and faster and a little more manageable)
I create an element that has an array of pages, then I check each element in the array to see if it is the current page. If it is, I add an active class.
Then I can call this item from anywhere.
// Changed the line below to a multi-dimensional array to cater for different controllers and actions //$mypages = array('Home','About','Pricing','FAQs','Contact'); $mypages = array( array('controller'=>'controller1','action'=>'action1','name'=>'name1'), array('controller'=>'controller2','action'=>'action2','name'=>'name2 ') ); foreach ($mypages as $page ){ // Changed to account for controller and action //$currentPage = isset($this->params['pass'][0]) ?$this->params['pass'][0] : ""; $controller = isset($this->request->params['controller'])?$this->request->params['controller']: ""; $action= isset($this->request->params['action'])?$this->request->params['action']: ""; if (strtolower($page['controller']) == $controller && strtolower($page['action']) == $action) { echo "<li class='active'>" . $this->Html->link($page,array("controller"=>"pages", "action"=>strtolower($page))) . "</li>" ; } else { echo "<li>" . $this->Html->link($page,array("controller"=>"pages", "action"=>strtolower($page))) . "</li>"; } }
source share