[CakePHP]How to create navigation with well thought out about current page


Using layout template is general at cakephp view. There is a global menu in layout template. If we show the selected global menu in each page even if it takes time a bit, it looks neat as the example below which I found at Google group.

<?php
$navLinks = array(
    'home' => array(
        'title' => 'home',
        'path' => '/',
    ),
    'services' => array(
        'title' => 'our services',
        'path' => '/pages/services',
    ),
    'contact' => array(
        'title' => 'contact us',
        'path' => '/contacts',
    ),
    'about' => array(
        'title' => 'about us',
        'path' => '/pages/about',
    ),
);
?>

<ul id="global_nav">
	<?php foreach ($navLinks as $key => $link) : 
		  
		  $class = null;
		  if (strpos($this->params['url']['url'], substr($link['path'], 1)) !== false) {
		      $class = array('class' => 'current');
		  }
	?>
	
	<li id="nav_<?=$key?>"><?=$html->link($link['title'], $link['path'], $class)?></li>
	<?php endforeach; ?>
</ul>
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
This entry was posted in CakePHP. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>