1 回答

TA貢獻2051條經驗 獲得超10個贊
您需要創建一個功能,然后在顯示頁面之前需要該功能。
首先,看一下local/readme.txt- 這給出了本地插件所需文件的概述。
或者閱讀https://docs.moodle.org/dev/Local_plugins上的文檔
還可以查看現有的本地插件,以便了解它們是如何創建的 - https://moodle.org/plugins/?q=type:local
至少,你需要
local/webguides/db/access.php - this will have the capability
local/webguides/lang/en/local_webguides.php
local/webguides/version.php
加上你的索引文件
local/webguides/index.php
在db/access.php文件中有類似的東西
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'local/webguides:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
),
),
);
您可能還需要'riskbitmask' => RISK_XXX取決于您的代碼中是否存在任何風險。如RISK_CONFIG,RISK_PERSONAL等
在lang/en/local_webguides.php有類似的東西
defined('MOODLE_INTERNAL') || die();
$string['pluginname'] = 'Webguides';
$string['webguides:view'] = 'Able to view webguids';
在version.php有類似的東西
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2020051901; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2015051109; // Requires this Moodle version.
$plugin->component = 'local_webguides'; // Full name of the plugin (used for diagnostics).
替換2015051109為您正在使用的 Moodle 版本 - 這將位于version.php根文件夾中。
然后在你的index.php文件中使用它靠近頂部。
require_capability('local/webguides:view', context_system::instance());
因此只有具有該能力的用戶才能訪問該頁面。
編輯:
settings.php您可以使用類似的方式添加鏈接
defined('MOODLE_INTERNAL') || die;
if ($hassiteconfig) {
$page = new admin_externalpage(
'local_webguides',
get_string('pluginname', 'local_webguides'),
new moodle_url('/local/webguides/index.php'),
'local/webguides:view'
);
$ADMIN->add('localplugins', $page);
}
然后在你的索引頁廣告這個
require_once($CFG->libdir.'/adminlib.php');
并刪除require_login()并require_capability()替換為
admin_externalpage_setup('local_webguides');
- 1 回答
- 0 關注
- 124 瀏覽
添加回答
舉報