-
Improvement
-
Resolution: Fixed
-
Minor
-
3.7.5, 3.8.2
-
MOODLE_37_STABLE, MOODLE_38_STABLE
-
MOODLE_39_STABLE
-
Code in a renderer should never refer to global $PAGE. The page this renderer is rendering should be accessed as $this->page.
Similarly, never refer to global $OUTPUT. If you need to access the core renderer from a plugin renderer, use $this->output.
99% of the time this does not matter, because each script is only rendering its own output. However, in theory it should be possible to write a script like to archive all quiz results:
foreach ($quizattempts as $attempt) { |
$reviewpage = new moodle_page(); |
// Setup $reviewpage; |
$output = $reviewpage->get_renderer('mod_quiz'); |
$html = $output->render_review_page($attempt); |
// Store $html in a zip file. |
}
|
If renderers refer to the global variables, this breaks .
We really ought to have a CodeChecker rule to catch people making this mistake, since it is clearly very easy to do.
- has a non-specific relationship to
-
MDL-82165 Avoid the use of global $PAGE in mod_feedback\output\edit_action_bar
-
- Open
-
-
CONTRIB-8031 CodeChecker should detect use of global $PAGE and $OUTPUT in renderers
-
- Closed
-