我有一个带有顶部导航栏的站点布局,我需要将类设置为活动,具体取决于当用户单击不同页面时更改的控制器.
则须─> index.phtml
 <li class='<?php echo (isset($this->controllerName) && $this->controllerName == 'about') ? 'active' : '' ?>'><a href="/about">About Us</a></li>
 <li class='<?php echo (isset($this->controllerName) && $this->controllerName == 'services') ? 'active' : '' ?>'><a href="/services">Member Sevices</a></li>
我希望Phalcon有一个视图功能,或者我可以把它放在引导程序中,所以它适用于所有页面而我不得不记住在每个Controller中手动设置controllerName变量.
Dav*_*can 13
在您的视图中访问您的路由器服务:
$this->router->getControllerName()
$this->router->getActionName()
或者如果你使用伏特,你可以使用短手
router.getControllerName()
router.getActionName()
这将适用于您的用例,但如果您发现您的菜单逻辑变得太笨重,有几种方法可以实现您尝试执行的操作.
我发现最简单的方法是使用javascript,但如果禁用js(1%)则没有后备.如果您想覆盖100%的受众,您可以使用Phalcon团队使用元素库在INVO中执行的方法:https://github.com/phalcon/invo/blob/master/app/library/Elements.php