The $PAGE global - what is it?

The $PAGE global - what is it?

von Justin Wyllie -
Anzahl Antworten: 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

 

Als Antwort auf Justin Wyllie

Re: The $PAGE global - what is it?

von 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 zwinkernd

hth
Frank
Als Antwort auf Frank Ralf

Re: The $PAGE global - what is it?

von 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

Als Antwort auf Justin Wyllie

Re: The $PAGE global - what is it?

von Tim Hunt -
Nutzerbild von Core developers Nutzerbild von Documentation writers Nutzerbild von Particularly helpful Moodlers Nutzerbild von Peer reviewers Nutzerbild von 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.