Note: You are currently viewing documentation for Moodle 2.3. Up-to-date documentation for the latest stable version is available here: lib/weblib.php moodle url.

Development:lib/weblib.php moodle url

From MoodleDocs
Revision as of 10:58, 20 May 2007 by Jamie Pratt (talk | contribs) (formatting)

Template:Moodle 1.9

moodle_url is a new class available from Moodle 1.9 onwards in weblib.php. It can be used in moodle pages where config.php has been included without any further includes.

It is useful for manipulating urls with long lists of params. One situation where it will be useful is a page which links to itself to perfrom various actions and / or to process form data. A moodle_url object :

  • can be created for a page to refer to itself with all the proper get params being passed from page call to page call
  • and methods can be used to output a url including all the params, optionally adding and overriding params
  • and can also be used to
    • output the url without any get params
    • and output the params as hidden fields to be output within a form

See phpdoc comments on methods for more information on the use of this class.

One important usage note is that data passed to methods out, out_action, get_query_string and hidden_params_out affect what is returned by the function and do not change the data stored in the object. This is to help with typical usage of these objects where one object is used to output urls in many places in a page.