The $PAGE global - what is it?

The $PAGE global - what is it?

by Justin Wyllie -
Number of replies: 4

Hi

My problem is on a page I wanted to get the course module id. The page was accessed off the Activity Module settings menu by clicking Permissions. The url of this page is WEBROOTadmin/roles/permissions.php?contextid=31. The course module id is not passed in the url so I can't get it with optional_param. However I can still obtain it from $PAGE->cm->id on this page.

Can someone tell me what $PAGE is? i have searched the docs and can't see it. The var_dump of it produces a 37 Mb file which is a bit difficult to understand.

Thanks.

Justin Wyllie

 

Average of ratings: -
In reply to Justin Wyllie

Re: The $PAGE global - what is it?

by Frank Ralf -
Hi Justin,

See Introduction to Moodle Programming - Unit 5 Part B: Global Variables (for Moodle 1.9).

You might also find the FirePHP plugin useful. But also have a look at YUI Logger settings in Moodle 2.0? if you find the output in the Firebug console too overwhelming wink

hth
Frank
In reply to Frank Ralf

Re: The $PAGE global - what is it?

by Justin Wyllie -

Thanks for the link Frank. Unfortunately nothing about $PAGE at that url. It covers some of the others but not $PAGE. Is that because $PAGE is new?

Thanks

 

Justin

In reply to Justin Wyllie

Re: The $PAGE global - what is it?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

$PAGE sort-of existed in 1.9, but is has changed completely changed in Moodle 2.0.

It is basically metadata about the page that is going to be displayed. A lot of the values are needed by $OUTPUT->header() and $OUTPUT->footer().

To make it work, at a very minimum you need to

  • Call require login with appropriate arguments. (You should be doing that anyway.)
  • Call $PAGE->set_url near the start of your script.

Look at some other moodle scripts that have been written recently be Moodle HQ developers who konw what they are doing, to see what else you shoudl be doing.

Average of ratings: Useful (1)