search
Homephp教程PHP源码moodle2.4 DIY 导航block的实例

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)!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.