问题
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