Home >Backend Development >PHP Tutorial >Laravel 5.1 高亮菜单

Laravel 5.1 高亮菜单

WBOY
WBOYOriginal
2016-06-23 13:25:431088browse

最近基于Laravel5.1做项目开发,后台菜单高亮,原来用jQuery做菜单高亮,但发现到了新方法里就不奏效了,还是在定义变量在View层判断即可。

基类

定义两个变量,并共享到所有模板里

class BaseController extends Controller{    public $module;    public $parent_module;    public function __construct()    {        View::share('active',[$this->module=>'active']);        View::share('parent_active',[$this->parent_module=>'active']);    }}

继承的类
(赋值变量)

class ShopCategoryTagController extends BaseController{    public $module = 'cate_tag';    public $parent_module = 'parent_shop';

视图层

父级

<li class="treeview {{isset($parent_active['parent_shop']) ? $parent_active['parent_shop'] : ''}}">

子级

<li class="{{isset($active['cate_tag']) ? $active['cate_tag'] : ''}}"><a href="{{url('admin/shop_category_tag')}}">

效果:

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn