Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我通过Moodle mForm中的参数访问过去的数据?_Php_Moodle - Fatal编程技术网

Php 我通过Moodle mForm中的参数访问过去的数据?

Php 我通过Moodle mForm中的参数访问过去的数据?,php,moodle,Php,Moodle,我需要获取“mForm”moodle表单的参数值,但不知道如何获取 我应该将静态字段“Date Created”添加到课程的编辑部分,而不是将其显示为Unix时间戳 对此,有以下几点: $fecha_creacion = date('m/d/Y', xxxxxxxxx); $mform->addElement('static', 'desc' , 'Fecha de Creación'); $mform->setDefault('desc', $fecha_creacion);

我需要获取“mForm”moodle表单的参数值,但不知道如何获取

我应该将静态字段“Date Created”添加到课程的编辑部分,而不是将其显示为Unix时间戳

对此,有以下几点:

$fecha_creacion = date('m/d/Y', xxxxxxxxx);

$mform->addElement('static', 'desc' , 'Fecha de Creación');

$mform->setDefault('desc', $fecha_creacion);
其中,“xxxxxxxx”是从“mdl_couse”表(“timecreated”)中的BD获得的整数值

因此,我需要获取整数值,它与传入的参数相同:

$mform->addElement('static', 'timecreated' , 'Fecha de Creación');
我是穆德尔的新手。
非常感谢。

Moodle使用HTML\u QuickForm,因此您应该能够在上查阅文档

如果我理解正确,在这种情况下,您需要以下内容:

$mform->getElementValue('timecreated');

希望这有帮助。

您可以将参数传递给表单

在edit.php文件中

// Get the course record that you want.
$course = $DB->get_record('course', array('id' => $id));

// Pass the time created value in an array.
$customdata = array('timecreated' => $course->timecreated);
$form = new edit_form(null, $customdata);
然后在edit_form.php文件中

class edit_form extends moodleform {

    public function definition() {

        $mform =& $this->_form;

        // Copy the timecreated value.
        $timecreated = $this->_customdata['timecreated'];
        // Pass timecreated as the 4th parameter - userdate() will display the date in the users locale.
        // You should also use get_string() to display the label in the users language.
        $mform->addElement('static', 'timecreated', get_string('timecreated', 'yourpluginname'), userdate($timecreated));

解决方案:

    $customdata = array('timecreated' => $course->timecreated);
    $fecha_c = $customdata['timecreated'];

要获得价值,请创建时间

    $fecha_creacion = date('d/m/Y',$fecha_creacion);
    $mform->addElement('static', 'desc' , 'Fecha de Creación');
    $mform->setDefault('desc', $fecha_creacion);
仅在课程版本中:(不适用于创建课程)


谢谢你的帮助

非常感谢你的回复,不幸的是不是我,但我会调查QuikForm,希望得到结果。非常感谢你的回复,我理解逻辑,但还没有给我方法结果,我一直在尝试看我得到了什么。发生的是页面正在加载,但什么都没有发生,好像在进行一项繁重的工作。
    $fecha_creacion = date('d/m/Y',$fecha_creacion);
    $mform->addElement('static', 'desc' , 'Fecha de Creación');
    $mform->setDefault('desc', $fecha_creacion);
    if (!empty($course->id)) {
        $fecha_c = $course->timecreated;
        $fecha_creacion = date('d/m/Y',$fecha_creacion);
        $mform->addElement('static', 'desc' , 'Fecha de Creación');
        $mform->setDefault('desc', $fecha_creacion);
    }