Rumah >php教程 >PHP源码 >moodle2.4 DIY 导航block的实例

moodle2.4 DIY 导航block的实例

PHP中文网
PHP中文网asal
2016-05-25 17:07:341237semak imbas

moodle2.4 DIY 导航block的实例

通过修改navigationlib.php文件来达到自定义导航的目的。

//这里我改成 这样 后面有一个配置文件 读取 导航菜单的数据
//moodle/lib/navigationlib.php 1261行 或者搜索 "// Remove any empty root nodes"
foreach ($this->rootnodes as $node) {
            // Dont remove the home node
            if ( $node->key !== 'courses' &&!in_array( $node->key , array(1,2,3,4,5,6,7,8,9)) ) {
                $node->remove();
            }
        }
//moodle/lib/navigationlib.php 1068行 或者搜索 "$this->rootnodes['users'] = $this->add(get_string('users'), null, self::TYPE_ROOTNODE, null, 'users');"

// @添加几行代码
        chmod( $CFG->dirroot . '/navigation.config.php' , 0777);
        $navigation_data = require( $CFG->dirroot . '/navigation.config.php');

        foreach ( $navigation_data as $key => $value) {
            $this->rootnodes[$key] = $this->add( $value['text'] , null , self::TYPE_ROOTNODE , null , $key);
            
            foreach( $value['branch'] as $url){
                $this->rootnodes[$key]->add_node( navigation_node::create( $url['text'], new moodle_url( $url['url']), self::NODETYPE_BRANCH, null, null, new pix_icon( $url['icon'] , '') ));
            }
        }



//现在写个根目录下的配置文件 navigation.config.php
<?php
return array(
	1 => array(
		&#39;text&#39; => &#39;学习中心&#39;,
		&#39;branch&#39; => array(
				0	=> array(
					&#39;text&#39;	=> &#39;我的课程&#39;,
					&#39;url&#39; 	=> &#39;/course/&#39;,
					&#39;icon&#39; 	=> &#39;i/db&#39;,
					),
				1 	=> array(
					&#39;text&#39;	=> &#39;成绩&#39;,
					&#39;url&#39;	=> &#39;/grades/&#39;,
					&#39;icon&#39;	=> &#39;i/manual_item&#39;,
					),
				2 	=> array(
					&#39;text&#39;	=>&#39;问答&#39;,
					&#39;url&#39;	=>&#39;/quest/&#39;,
					&#39;icon&#39;	=>&#39;i/feedback&#39;,
					),

		),
	),

	2 => array(
		&#39;text&#39; => &#39;账户管理&#39;,
		&#39;branch&#39; => array(
				0	=> array(
					&#39;text&#39;	=>&#39;账户&#39;,
					&#39;url&#39;	=>&#39;/user/&#39;,
					&#39;icon&#39;	=>&#39;i/lock&#39;,
				),

				1	=> array(
					&#39;text&#39;	=>&#39;订单&#39;,
					&#39;url&#39;	=>&#39;/order/&#39;,
					&#39;icon&#39;	=>&#39;i/payment&#39;,
				),
		),
	),
);
再刷新 moodle页面,导航就被修改成自己需要的样子了。因为moodle不带自定义功能,所以只能这样修改

                   

 以上就是moodle2.4 DIY 导航block的实例的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn