moodle2.4 DIY 导航block的实例

通过修改navigationlib.php文件来达到自定义导航的目的。  这个是简单的demo。 //这里我改成 这样 后面有一个配置文件 读取 导航菜单的数据 //mo…

通过修改navigationlib.php文件来达到自定义导航的目的。 
这个是简单的demo。

  1. //这里我改成 这样 后面有一个配置文件 读取 导航菜单的数据
  2. //moodle/lib/navigationlib.php 1261行 或者搜索 “// Remove any empty root nodes”
  3. foreach ($this->rootnodes as $node) {
  4.             // Dont remove the home node
  5.             if ( $node->key !== ‘courses’ &&!in_array( $node->key , array(1,2,3,4,5,6,7,8,9)) ) {
  6.                 $node->remove();
  7.             }
  8.         }
  9. //moodle/lib/navigationlib.php 1068行 或者搜索 “$this->rootnodes[‘users’] = $this->add(get_string(‘users’), null, self::TYPE_ROOTNODE, null, ‘users’);”
  10. // @添加几行代码
  11.         chmod( $CFG->dirroot . ‘/navigation.config.php’ , 0777);
  12.         $navigation_data = require( $CFG->dirroot . ‘/navigation.config.php’);
  13.         foreach ( $navigation_data as $key => $value) {
  14.             $this->rootnodes[$key] = $this->add( $value[‘text’] , null , self::TYPE_ROOTNODE , null , $key);
  15.             
  16.             foreach( $value[‘branch’] as $url){
  17.                 $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’] , ”) ));
  18.             }
  19.         }
  20. //现在写个根目录下的配置文件 navigation.config.php
  21. <?php
  22. return array(
  23.         1 => array(
  24.                 ‘text’ => ‘学习中心’,
  25.                 ‘branch’ => array(
  26.                                 0        => array(
  27.                                         ‘text’        => ‘我的课程’,
  28.                                         ‘url’         => ‘/course/’,
  29.                                         ‘icon’         => ‘i/db’,
  30.                                         ),
  31.                                 1         => array(
  32.                                         ‘text’        => ‘成绩’,
  33.                                         ‘url’        => ‘/grades/’,
  34.                                         ‘icon’        => ‘i/manual_item’,
  35.                                         ),
  36.                                 2         => array(
  37.                                         ‘text’        =>’问答’,
  38.                                         ‘url’        =>’/quest/’,
  39.                                         ‘icon’        =>’i/feedback’,
  40.                                         ),
  41.                 ),
  42.         ),
  43.         2 => array(
  44.                 ‘text’ => ‘账户管理’,
  45.                 ‘branch’ => array(
  46.                                 0        => array(
  47.                                         ‘text’        =>’账户’,
  48.                                         ‘url’        =>’/user/’,
  49.                                         ‘icon’        =>’i/lock’,
  50.                                 ),
  51.                                 1        => array(
  52.                                         ‘text’        =>’订单’,
  53.                                         ‘url’        =>’/order/’,
  54.                                         ‘icon’        =>’i/payment’,
  55.                                 ),
  56.                 ),
  57.         ),
  58. );
  59. 再刷新 moodle页面,导航就被修改成自己需要的样子了。因为moodle不带自定义功能,所以只能这样修改

复制代码

作者: admin

为您推荐

联系我们

联系我们

邮箱:

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部