using redirect in moodle 2.0

using redirect in moodle 2.0

door Joseph Rézeau -
Aantal antwoorden: 2
Foto van Core developers Foto van Particularly helpful Moodlers Foto van Plugin developers Foto van Testers Foto van Translators
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()

Gemiddelde van de beoordelingen:  -
Als antwoord op Joseph Rézeau

Re: using redirect in moodle 2.0

door Tim Hunt -
Foto van Core developers Foto van Documentation writers Foto van Particularly helpful Moodlers Foto van Peer reviewers Foto van Plugin developers
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.
Gemiddelde van de beoordelingen: Useful (2)