douan2907 2018-07-10 01:35
浏览 110
已采纳

Moodle3.5 ::课程的课程模块

Get course modules for a course:

I was trying to get course modules for current courseid. Tried to pull out the array values with print_r and var_dump, not with exact string conversion.

I was looking for module instance or module id and module name (modname) from the array output.

I want the course modules from the course, displays coursename, modules on a custom page.

global $DB;
$course = $DB->get_record('course', array('id' => $courseid));
$info = get_fast_modinfo($course);
print_r($info);
//var_dump($info);
  • 写回答

1条回答 默认 最新

  • douduan9391 2018-07-10 04:35
    关注

    The code you need is as follows:

    $modinfo = get_fast_modinfo($courseid);
    foreach ($modinfo->get_cms() as $cminfo) {
        echo $cminfo->id.' ('.$cminfo->instance.'): '.$cminfo->get_formatted_name().'<br>';
    }
    

    Have a look at lib/modinfolib.php, class course_modinfo for details of the functions you can call on the object returned by get_fast_modinfo(). Look at the cm_info class in the same file for details for the object returned by get_cms() / get_cm($cmid).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了