In the course of re-factoring a module for moodle 2.0 I am getting the following error. Can someone point me to some examples of best strategy to avoid this error in the new moodle 2.0 API? Thanks,
Joseph
You should really redirect before you start page output
* line 562 of \lib\outputrenderers.php: call to debugging()
* line 2602 of \lib\weblib.php: call to core_renderer->redirect_message()
Generally, a Moodle script should look like this:
require_once('config.php');
// Calls to optional_param and/or required_param.
// Initialise $PAGE.
$PAGE->set_url(...);
// Check permissions.
require_login(...);
require_capability(...);
// See if there is any submitted data.
// If so process it, and then redirect.
// Otherwise
echo $OUTPUT->header();
// Output the body of the page.
echo $OUTPUT->footer();
One feature of that is that every call to redirect is before the call to $OUTPUT->header();. The same applies in Moodle 1.9. All calls to redirect should be before print_header.
An example is http://cvs.moodle.org/moodle/course/request.php?view=markup. Actually, I think there is a small but there. There is a call to notice that I think should be a call to redirect.
http://cvs.moodle.org/moodle/course/pending.php?view=markup is a slightly more complex example.
require_once('config.php');
// Calls to optional_param and/or required_param.
// Initialise $PAGE.
$PAGE->set_url(...);
// Check permissions.
require_login(...);
require_capability(...);
// See if there is any submitted data.
// If so process it, and then redirect.
// Otherwise
echo $OUTPUT->header();
// Output the body of the page.
echo $OUTPUT->footer();
One feature of that is that every call to redirect is before the call to $OUTPUT->header();. The same applies in Moodle 1.9. All calls to redirect should be before print_header.
An example is http://cvs.moodle.org/moodle/course/request.php?view=markup. Actually, I think there is a small but there. There is a call to notice that I think should be a call to redirect.
http://cvs.moodle.org/moodle/course/pending.php?view=markup is a slightly more complex example.
Thank you for your explanations, Tim. I've got it to work now.
Joseph
Joseph