Hello everyone,
I'm using Moodle 3.8.1+
I am looking for the right way to create a stand-alone page that is in Moodle but not associated with any course, module, report or admin/local plugin.
We have a folder (/pages) with .php pages in them that are utilizing a method that used to work nicely without any debug messages but now it shows a debug message of the following:
Coding problem: $PAGE->context was not set. You may have forgotten to call require_login() or $PAGE->set_context(). The page may not display correctly as a result
line 503 of \lib\pagelib.php: call to debugging()
line 830 of \lib\pagelib.php: call to moodle_page->magic_get_context()
line 1456 of \lib\weblib.php: call to moodle_page->__get()
line 1233 of \lib\pagelib.php: call to format_string()
line 11 of \pages\libraryresources.php: call to moodle_page->set_title()
I found some old references to this being thrown by improper plugins, but nothing reported in the past was related to my specific case, of a stand-alone page.
I've tried setting $PAGE->set_context() passing the instance of the application (front page is course id 1).
The advice provided in the past for this debug message (which is related to an errant plugin) said to comment out lines 501-503 in /lib/pagelib.php to make the debug message go away but I'm actually looking for a real cure to this. I don't quite understand yet the reason why this is being triggered since this page code used to work just fine even when debug messages were being shown. I'm talking about previous to Moodle version 3.6.x
Here's an example of my one of my stand-alone page code for the top portion of a page. Can anyone tell me if I'm doing something I should not be doing or if this scenario of a stand-alone page is not able to be supported by Moodle? Thanks so much!
Code of /pages/libraryresources.php:
<?php
require_once("../config.php");
global $CFG, $SITE, $PAGE, $OUTPUT, $DB;
require_login();
$PAGE->set_pagetype('site-index');
$PAGE->set_pagelayout('incourse');
$PAGE->set_title("Library Resources");
$PAGE->set_heading($SITE->fullname);
$PAGE->set_url("/");
$context = context_system::instance();
$PAGE->set_context($context);
echo $OUTPUT->header();
echo $OUTPUT->heading("Library Resources");
echo $OUTPUT->box_start('maintenance_message generalbox boxwidthwide boxaligncenter');
?>
after this code, custom html is provided, and then the footer code (below) is called:
<?php echo $OUTPUT->box_end(); echo $OUTPUT->footer(); die(); exit;