Moodle块的正确上下文ID是什么 [英] What is the correct context id of Moodle block

查看:167
本文介绍了Moodle块的正确上下文ID是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

面条块 block_html的正确context id是什么.

案例1

block_html.php文件

$this->context->id给出 122

案例2

我创建一个名为view.php的新页面.在这里我尝试

I create a new page named view.php. Here I try

$instance = $DB->get_record('block_instances', array('id' => 57));
$blockname = 'html';
$block = block_instance($blockname, $instance);
echo $block->context->id;

这给出了 98 .

案例3

$context = context_block::instance($cmid);

echo $context->id

给出 7

我应该用什么作为block_htmlcontext id.我需要确切的context id.

What should I use as context id of block_html. I need the exact context id.

注意:对于所有块,我都遇到上述问题.我怎么了?

Note: For all blocks I am getting the issue described above. What is the wrong I used?

推荐答案

案例1和2 应该正确.

block::get_content()中,可以肯定地使用$this->context获得块的正确上下文.

In block::get_content() you get the right context of the block using $this->context, for sure.

要手动获取块的上下文,请执行context_block::instance($instanceid).我怀疑在您的示例中,您错误地使用了错误的块实例ID.您可以使用$this->context->instanceidget_content获取块实例ID.

To manually get the context of a block you do context_block::instance($instanceid). I suspect is that in your example you mistakenly used the wrong block instance ID. You can get the block instance ID from get_content using $this->context->instanceid.

这篇关于Moodle块的正确上下文ID是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆