jordanvg / cakephp-menu-helper Goto Github PK
View Code? Open in Web Editor NEWSimple helper for CakePHP that detects if a link routes to the current controller and styles a list element accordingly.
Simple helper for CakePHP that detects if a link routes to the current controller and styles a list element accordingly.
Hi
The view content examples a missing brackets, one near the end of each line.
I faced a problem with multiple static routes. In my case I've this :
Router::connect('/home', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/lesson', array('controller' => 'pages', 'action' => 'display', 'lesson'));
they point on home and lesson ctp file in my views folder
And my link look like this :
Menu->item($this->Html->link('Home', '/home')); ?>
Menu->item($this->Html->link('Lesson', '/lesson')); ?>
The problem is that your helper only test the controler and the action. If I click on home, the lesson menu is also active and vice versa.
So I've made some change in your function, maybe need some improvement.
if ($this->params['controller'] == $linkRoutes['controller'] && $this->params['action'] == $linkRoutes['action']) {
if (isset($attributes['class'])) {
$classes = explode(' ', $attributes['class']);
$classes[] = $activeClass;
$attributes['class'] = $classes;
}
else {
if(!empty($linkRoutes['pass'][0])){
if($linkRoutes['pass'][0] == $this->params['pass'][0]){
$attributes['class'] = $activeClass;
}
}else{
$attributes['class'] = $activeClass;
}
}
}
Hope this can help.
Requires
App::uses('Xml', 'Utility');
in MenuHelper.php if the user isn't already using it elsewhere
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.