3

我正在为 Moodle 开发一个模块。我已经实现在课程中安装和实例化它。问题是,在启用“编辑模式”时,我会收到以下消息:

The module mymodule does not define the standard capability mod/mymodule:addinstance

    line 3451 of \course\lib.php: call to debugging()
    line 1899 of \course\lib.php: call to course_allowed_module()
    line 1767 of \course\lib.php: call to get_module_metadata()
    line 682 of \course\format\renderer.php: call to print_section_add_menus()
    line 49 of \course\format\weeks\format.php: call to format_section_renderer_base->print_multiple_section_page()
    line 276 of \course\view.php: call to require()

/mod/mymodule/db/access.php文件中,我有以下代码:

defined('MOODLE_INTERNAL') || die();

$capabilities = array(
    'mod/mymodule:view' => array(
        'captype' => 'read',
        'contextlevel' => CONTEXT_MODULE,
        'legacy' => array(
            'guest' => CAP_ALLOW,
            'student' => CAP_ALLOW,
            'teacher' => CAP_ALLOW,
            'editingteacher' => CAP_ALLOW,
            'admin' => CAP_ALLOW
        )
    ),

    'mod/mymodule:submit' => array(
        'riskbitmask' => RISK_SPAM,
        'captype' => 'write',
        'contextlevel' => CONTEXT_MODULE,
        'legacy' => array(
            'student' => CAP_ALLOW
        )
    ),
);

我是 Moodle 模块开发的初学者。我已阅读以下文档:

但我没有澄清任何事情。

2013-04-28 编辑

我已将此代码添加到我的 access.php 文件($capabilities 数组)中:

'mod/mymodule:myaddinstance' => array(
                'captype' => 'write',
                'contextlevel' => CONTEXT_SYSTEM,
                'archetypes' => array(
                        'user' => CAP_ALLOW
                ),

                'clonepermissionsfrom' => 'moodle/my:manageblocks'
        ),

        'mod/mymodule:addinstance' => array(
                'riskbitmask' => RISK_SPAM | RISK_XSS,

                'captype' => 'write',
                'contextlevel' => CONTEXT_MODULE,
                'archetypes' => array(
                        'editingteacher' => CAP_ALLOW,
                        'manager' => CAP_ALLOW
                ),

                'clonepermissionsfrom' => 'moodle/site:manageblocks'
        ),

但它不起作用。

4

1 回答 1

3

起初,这似乎是一条奇怪的错误消息,因为它提到mod/mymodule:addinstance但您的代码中没有。但仔细观察,这似乎是问题所在——moodle 期望你定义addinstance,但你没有!

这显然是从 2.4 开始的新行为:http: //docs.moodle.org/dev/Blocks#db.2Faccess.php

解决方案似乎是将addinstance(并且可能myaddinstance,取决于您的设置和实现)添加到您的$capabilities数组中。

于 2013-04-28T08:56:51.043 回答