简体   繁体   English

CodeIgniter / Pyrocms-如何更改自定义模块的子导航以适合该部分?

[英]CodeIgniter / Pyrocms - how do I make my custom modules sub-navigation alter to suit the section?

I'm making a custom module for PyroCMS, and I want to get the section menu working with regard to applying the current class. 我正在为PyroCMS创建一个自定义模块,并且我想让该部分菜单在应用当前类方面起作用。 The CMS php, which I don't want to change looks like this: 我不想更改的CMS php看起来像这样:

<li class="<?php if ($name === $active_section) echo 'current' ?>">

When I'm viewing /admin/courses/ this is correct, and the first navigation element has the class, current. 当我查看/ admin / courses /时,这是正确的,并且第一个导航元素具有当前类。

在此处输入图片说明

$name is taken from the language file, as set up in details.php. $ name取自在details.php中设置的语言文件。 $active_section is taken from the view, and is equal to $ active_section是从视图中获取的,等于

$this->_ci_cached_vars['active_section'] $ this-> _ ci_cached_vars ['active_section']

However when I view /admin/courses/chapters/, 'courses' is still determined by the system to be the current section, so the navigation is confusing. 但是,当我查看/ admin / courses / chapters /时,系统仍将“课程”确定为当前部分,因此导航令人困惑。

What I need is a way of changing the value of $active_session in the view acording to which function of the controller (index, chapters or pages) is being used. 我需要的是一种根据所使用的控制器功能(索引,章节或页面)在视图中更改$ active_session值的方法。

I've tried changing the value of $this->_ci_cached_vars['active_section'] in each controller function, but that doesn't work. 我尝试在每个控制器函数中更改$ this-> _ ci_cached_vars ['active_section']的值,但这不起作用。 Any ideas? 有任何想法吗?

I'm sure there's something basic I'm missing completely. 我敢肯定,我完全缺少一些基本的东西。

Got it. 得到它了。 I'm using multiple methods in one controller, and the 'protected $section = 'courses'; 我在一个控制器中使用多种方法,并且'protected $ section ='courses'; line, which happens before the index method, was setting the section for everything. 这行发生在index方法之前,它为所有内容设置了部分。 It couldn't be set a second time within another method, but there is a way to define a section within a method. 不能在另一个方法中第二次设置它,但是有一种方法可以在一个方法中定义一个节。

$this->template->active_section = 'section'; $ this-> template-> active_section ='section'; Starting my method as follows gave me what I wanted. 如下所述开始我的方法就给了我想要的东西。

public function chapters(){

        //Set active section
        $this->template->active_section = 'chapters';
 ...

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM