I\'m creating an accordion layout for an admin sidebar. Now I need to identify the active link and add a class active
to that link. Here is my code:
<
I know this is pretty old but i found a good solution.
Based on Faisal's answer i wrote my own simple Helper:
App::uses('AppHelper', 'View/AppHelper');
class PVHtmlHelper extends AppHelper {
public $helpers = array('Html');
public function link($title = null, $url = null, $options) {
if ($title == null || $url == null)
return;
$class = (($this->params['controller']===$url['controller']) && ($this->params['action']==$url['action']) )?'active' :'';
echo "- " . $this->Html->link($title, $url, $options) . "
";
}
}
Maybe you need to modify the echo
inside the function to fit your needs.
Example:
echo $this->PVHtml->link('Login', array('controller' => 'users', 'action' => 'login'));