【问题标题】:Create Course API not working in Moodle创建课程 API 在 Moodle 中不起作用
【发布时间】:2015-11-10 01:15:17
【问题描述】:

我是 Moodle 的新手。我已经使用 Web 服务 api 创建了用户,并且运行成功。现在我想以同样的方式创建一门课程。我正在使用“core_course_create_courses”函数来执行此操作。我的请求的帖子正文是

$courses=array("courses" =>
            array(
                0=>array(
                    "fullname" => $fullname,
                    "shortname" => $shortname,
                    "categoryid" => $categoryid,
                    "idnumber" =>$idnumber,
                    "summary"=>$summary,
                    "summaryformat"=>$summaryformat
                )
            )
        );

每当我运行它时,它都会给我响应 "{\"exception\":\"moodle_exception\",\"errorcode\":\"errorcatcontextnotvalid\",\"message\":\"您不能在类别上下文(类别 id:101)中执行函数。上下文错误消息是:检测到无效的参数值\“}”

但是在我的 moodle 网站中存在 ID 为 101 的课程类别“编程”。请帮我。提前致谢。

【问题讨论】:

    标签: php web-services api post moodle


    【解决方案1】:

    我错了,categoryid不是类别的id,是类别的序列id。现在如果我给2,它就可以了。

    【讨论】:

      【解决方案2】:
      $token = $this->config->item('id_token');
          $domainname = $this->config->item('domainname');
          $functionname = 'core_course_create_courses';
          $restformat = 'json';
      
          //crear objeto de acuerdo a la estructura para crear Categoría en Moodle
      
          $curso = new stdClass();        
          $curso->fullname = $data['patron']['nombre']; 
          $curso->shortname = $data['patron']['nombre']; // Is unique
          **$curso->idnumber = $id; // consecutive
          $curso->visible = 1;
          $curso->categoryid = 6; 
      
          $modulos = array($curso);
      
          $params = array('courses' => $modulos);
      
          header('Content-Type: text/plain');
          $serverurl = $domainname . '/webservice/rest/server.php' . '?wstoken=' . $token . '&wsfunction=' . $functionname;
          require_once(APPPATH . 'libraries/curl.php');
          $curl = new curl;
      
          $restformat = ($restformat == 'json') ? '&moodlewsrestformat=' . $restformat : '';
          $resp = $curl->post($serverurl . $restformat, $params);
          return $resp;
      

      【讨论】:

        猜你喜欢
        • 2015-12-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-08
        • 2021-07-04
        • 2016-12-01
        相关资源
        最近更新 更多