Skip to content

Instantly share code, notes, and snippets.

@tekkub
Forked from jpdelatorre/display.php
Created December 14, 2009 20:10
Show Gist options
  • Save tekkub/256378 to your computer and use it in GitHub Desktop.
Save tekkub/256378 to your computer and use it in GitHub Desktop.
<?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