代码之家  ›  专栏  ›  技术社区  ›  Ashraf Hefny

表单元素filepicker和文件管理器未按$mform->addElement('filepicker'…..)显示错误代码:noguest

  •  1
  • Ashraf Hefny  · 技术社区  · 8 年前

    我试图在moodle v3中添加注册表单中的上传文件输入
    使用 $mform->addElement('filepicker' .... ) 在里面 moodle/login/signup_form.php

    但我得到了这个错误:
    Error code: noguest

    Stack trace:
    
    line 488 of /lib/setuplib.php: moodle_exception thrown
    line 348 of /lib/filelib.php: call to print_error()
    line 131 of /lib/form/filepicker.php: call to file_get_unused_draft_itemid()
    line 189 of /lib/pear/HTML/QuickForm/Renderer/Tableless.php: call to MoodleQuickForm_filepicker->toHtml()
    line 2806 of /lib/formslib.php: call to HTML_QuickForm_Renderer_Tableless->renderElement()
    line 408 of /lib/pear/HTML/QuickForm/element.php: call to MoodleQuickForm_Renderer->renderElement()
    line 1639 of /lib/pear/HTML/QuickForm.php: call to HTML_QuickForm_element->accept()
    line 1714 of /lib/formslib.php: call to HTML_QuickForm->accept()
    line 1682 of /lib/pear/HTML/QuickForm.php: call to MoodleQuickForm->accept()
    line 442 of /lib/pear/HTML/Common.php: call to HTML_QuickForm->toHtml()
    line 204 of /lib/pear/HTML/QuickForm/DHTMLRulesTableless.php: call to HTML_Common->display()
    line 933 of /lib/formslib.php: call to HTML_QuickForm_DHTMLRulesTableless->display()
    line 117 of /login/signup.php: call to moodleform->display()
    

    所以我认为这意味着来宾用户不允许使用filepicker

    2 回复  |  直到 8 年前
        1
  •  0
  •   user1530848    8 年前

    若您仍然希望在注册表单中添加filepicker,则需要修改以下代码。

    1./lib/filelib。php(编辑以下函数)

         function file_get_unused_draft_itemid() {
          if (isguestuser() or !isloggedin()) {
          //  print_error('noguest');
        }
        }
    

    简而言之,注释“print_error('noguest')”行。

    1. /lib/dml/moodle_database。php(编辑以下函数)

       public function get_record_select($table, $select, array   $params=null,$fields='*',$strictness=IGNORE_MISSING){
      if ($select) {
          $select = "WHERE $select";
      }
      try {
          return $this->get_record_sql("SELECT $fields FROM {" . $table . "} $select", $params, $strictness);
      } catch (dml_missing_record_exception $e) {
          if (!isloggedin()){}
          else{
          // create new exception which will contain correct table name
          throw new dml_missing_record_exception($table, $e->sql, $e->params);
          }
      }
      }
      

        2
  •  0
  •   Ashraf Hefny    8 年前

    如果有人需要答案,我终于找到了解决办法。

    但首先 来宾用户无法使用的原因 filepaicker/filemanager 文件区域的草稿文件基于用户ID存储,访客用户不应在系统中存储数据(否则,以“访客”身份登录的不同用户可能会访问彼此的草稿文件)。

    解决方案是: 使用 $mform->addElement('file' .... ) 和使用 正则表达式 具有 $mform->addRule() 验证如下:

    $mform->addRule('document_1', 'Error (allowed extensions are .jpg, .png and .pdf)', 'filename', 'myregex');