douan2907
2018-07-10 09:35
浏览 94
已采纳

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

图片转代码服务由CSDN问答提供 功能建议

获取课程的课程模块:

我试图获得课程 当前课程的模块。 试图用print_r和var_dump取出数组值,而不是精确的字符串转换。

我正在从数组输出中寻找模块实例或模块ID和模块名称(modname)。

我想要课程中的课程模块,在自定义页面上显示coursename,模块。

  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 12: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).

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题