gpt4 book ai didi

PHP - Exception Class not found - wrong namespace(PHP-未找到异常类-命名空间错误)

转载 作者:bug小助手 更新时间:2023-10-24 22:40:20 26 4
gpt4 key购买 nike



After instantiating moodle "externally" through

在“外部”实例化Moodle之后


require_once('../config.php');

in a SSO scenario inside an application (namely MRBS), i get an error: Exception - Class "MRBS\Session\context_block" not found when it comes to find out if the currently logged user has some capability on a specific block:

在应用程序(即MRB)内的SSO场景中,在确定当前登录的用户是否对特定块具有某些功能时,我收到一个错误:异常-找不到类“MRBS\SESSION\CONTEXT_BLOCK”:


if (has_capability('moodle/block:edit', context_block::instance($blockid)){}

I guess it is because the namespace is set to namespace MRBS\Session;

我猜是因为名称空间设置为名称空间MRBS\Session;


How can I correctly refer to context_block::instance()?

如何正确引用CONTEXT_BLOCK::INSTANCE()?


Moodle functions apparently work (e.g. require_login(), has_capability).
Thanks

Moodle函数显然是有效的(例如,Require_LOGIN()、HAS_CAPAILITY)。谢谢


更多回答
优秀答案推荐

You need to either write:

您需要编写以下内容:


if (has_capability('moodle/block:edit', \context_block::instance($blockid)) {}

With the '\' character to declare that context_block is in the top-level namespace.

使用‘\’字符声明CONTEXT_BLOCK位于顶级命名空间中。


Or you need to put the following at the top of your file:

或者,您需要将以下内容放在文件的顶部:


use \context_block;

Personally I prefer the first option, but it is generally a matter of personal preference.

就我个人而言,我更喜欢第一种选择,但这通常是个人喜好的问题。


更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com