What is the correct context id of Moodle block

丶灬走出姿态 提交于 2019-12-25 08:04:29

问题


What is the correct context id of Moodle block, block_html.

case1

In block_html.php file

$this->context->id inside get_content function gives 122

case2

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;

and this gives 98.

case3

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

echo $context->id

gives 7

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:


Case 1 and 2 should be correct.

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

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.



来源:https://stackoverflow.com/questions/40085222/what-is-the-correct-context-id-of-moodle-block

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!