-
-
Save tekkub/256378 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DisplayHelper extends AppHelper { | |
var $helpers = array('Html'); | |
/** | |
* | |
* Display navigation and detects currect page and adds 'active' class | |
* to the <li> tag | |
* | |
*/ | |
function navigation() { | |
$nav = array( | |
'Home' => '/', | |
'About' => 'about', | |
'Login' => 'users/login', | |
'Sign up' => 'users/signup' | |
); | |
$url_string = $this->params['url']['url']; | |
$output = '<ul>'; | |
foreach($nav as $label => $url) { | |
$li_class = ''; | |
if(($url == $url_string) || ((false !== strpos($url_string, $url) && $url != '/'))) { | |
$li_class = ' class="active"'; | |
} | |
$output .= '<li' . $li_class . '>' . $this->Html->link($label, '/'.$url) . '</li>'; | |
} | |
$output .= '</ul>'; | |
return $output; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment