Class for creating and manipulating urls.
More...
|
| __construct ($url, array $params=null, $anchor=null) |
| Create new instance of moodle_url. More...
|
|
| __toString () |
| Shortcut for printing of encoded URL. More...
|
|
| compare (moodle_url $url, $matchtype=URL_MATCH_EXACT) |
| Compares this moodle_url with another. More...
|
|
| get_host () |
| Returns the 'host' portion of a URL. More...
|
|
| get_param ($name) |
| Returns a given parameter value from the URL. More...
|
|
| get_path ($includeslashargument=true) |
| Returns the 'path' portion of a URL. More...
|
|
| get_port () |
| Returns the 'port' portion of a URL. More...
|
|
| get_query_string ($escaped=true, array $overrideparams=null) |
| Get the params as as a query string. More...
|
|
| get_scheme () |
| Returns the 'scheme' portion of a URL. More...
|
|
| out ($escaped=true, array $overrideparams=null) |
| Output url. More...
|
|
| out_as_local_url ($escaped=true, array $overrideparams=null) |
| Returns URL a relative path from $CFG->wwwroot. More...
|
|
| out_omit_querystring ($includeanchor=false) |
| Returns url without parameters, everything before '?'. More...
|
|
| param ($paramname, $newvalue='') |
| Add a param to the params for this url. More...
|
|
| params (array $params=null) |
| Add an array of params to the params for this url. More...
|
|
| raw_out ($escaped=true, array $overrideparams=null) |
| Output url without any rewrites. More...
|
|
| remove_all_params ($params=null) |
| Remove all url parameters. More...
|
|
| remove_params ($params=null) |
| Remove all params if no arguments passed. More...
|
|
| set_anchor ($anchor) |
| Sets the anchor for the URI (the bit after the hash) More...
|
|
| set_scheme ($scheme) |
| Sets the scheme for the URI (the bit before ://) More...
|
|
| set_slashargument ($path, $parameter='file', $supported=null) |
| Sets the url slashargument value. More...
|
|
|
static | make_draftfile_url ($draftid, $pathname, $filename, $forcedownload=false) |
| Factory method for creation of url pointing to draft file of current user. More...
|
|
static | make_file_url ($urlbase, $path, $forcedownload=false) |
| General moodle file url. More...
|
|
static | make_legacyfile_url ($courseid, $filepath, $forcedownload=false) |
| Factory method for creating of links to legacy course files. More...
|
|
static | make_pluginfile_url ($contextid, $component, $area, $itemid, $pathname, $filename, $forcedownload=false, $includetoken=false) |
| Factory method for creation of url pointing to plugin file. More...
|
|
static | make_webservice_pluginfile_url ($contextid, $component, $area, $itemid, $pathname, $filename, $forcedownload=false) |
| Factory method for creation of url pointing to plugin file. More...
|
|
|
string | $anchor = null |
| Anchor, may be also empty, null means none.
|
|
string | $host = '' |
| Hostname.
|
|
array | $params = array() |
| Url parameters as associative array.
|
|
string | $pass = '' |
| Password for http auth.
|
|
string | $path = '' |
| Script path.
|
|
int | $port = '' |
| Port number, empty means default 80 or 443 in case of http.
|
|
string | $scheme = '' |
| Scheme, ex. More...
|
|
string | $slashargument = '' |
| Optional slash argument value.
|
|
string | $user = '' |
| Username for http auth.
|
|
Class for creating and manipulating urls.
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 perform 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
- Copyright
- 2007 jamiesensei @externalurl http://docs.moodle.org/dev/lib/weblib.php_moodle_url See short write up here
- License
- http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
◆ __construct()
moodle_url::__construct |
( |
|
$url, |
|
|
array |
$params = null , |
|
|
|
$anchor = null |
|
) |
| |
Create new instance of moodle_url.
- Parameters
-
moodle_url | string | $url | - moodle_url means make a copy of another moodle_url and change parameters, string means full url or shortened form (ex.: '/course/view.php'). It is strongly encouraged to not include query string because it may result in double encoded values. Use the $params instead. For admin URLs, just use /admin/script.php, this class takes care of the $CFG->admin issue. |
array | $params | these params override current params or add new |
string | $anchor | The anchor to use as part of the URL if there is one. |
- Exceptions
-
◆ __toString()
moodle_url::__toString |
( |
| ) |
|
Shortcut for printing of encoded URL.
- Return values
-
◆ compare()
Compares this moodle_url with another.
See documentation of constants for an explanation of the comparison flags.
- Parameters
-
moodle_url | $url | The moodle_url object to compare |
int | $matchtype | The type of comparison (URL_MATCH_BASE, URL_MATCH_PARAMS, URL_MATCH_EXACT) |
- Return values
-
◆ get_host()
◆ get_param()
moodle_url::get_param |
( |
|
$name | ) |
|
Returns a given parameter value from the URL.
- Parameters
-
string | $name | Name of parameter |
- Return values
-
string | Value of parameter or null if not set |
◆ get_path()
moodle_url::get_path |
( |
|
$includeslashargument = true | ) |
|
Returns the 'path' portion of a URL.
For example, if the URL is http://www.example.org:447/my/file/is/here.txt?really=1 then this will return '/my/file/is/here.txt'.
By default the path includes slash-arguments (for example, '/myfile.php/extra/arguments') so it is what you would expect from a URL path. If you don't want this behaviour, you can opt to exclude the slash arguments. (Be careful: if the $CFG variable slasharguments is disabled, these URLs will have a different format and you may need to look at the 'file' parameter too.)
- Parameters
-
bool | $includeslashargument | If true, includes slash arguments |
- Return values
-
◆ get_port()
◆ get_query_string()
moodle_url::get_query_string |
( |
|
$escaped = true , |
|
|
array |
$overrideparams = null |
|
) |
| |
Get the params as as a query string.
This method should not be used outside of this method.
- Parameters
-
bool | $escaped | Use & as params separator instead of plain & |
array | $overrideparams | params to add to the output params, these override existing ones with the same name. |
- Return values
-
string | query string that can be added to a url. |
◆ get_scheme()
moodle_url::get_scheme |
( |
| ) |
|
◆ make_draftfile_url()
static moodle_url::make_draftfile_url |
( |
|
$draftid, |
|
|
|
$pathname, |
|
|
|
$filename, |
|
|
|
$forcedownload = false |
|
) |
| |
|
static |
Factory method for creation of url pointing to draft file of current user.
- Parameters
-
int | $draftid | draft item id |
string | $pathname | |
string | $filename | |
bool | $forcedownload | |
- Return values
-
◆ make_file_url()
static moodle_url::make_file_url |
( |
|
$urlbase, |
|
|
|
$path, |
|
|
|
$forcedownload = false |
|
) |
| |
|
static |
General moodle file url.
- Parameters
-
string | $urlbase | the script serving the file |
string | $path | |
bool | $forcedownload | |
- Return values
-
◆ make_legacyfile_url()
static moodle_url::make_legacyfile_url |
( |
|
$courseid, |
|
|
|
$filepath, |
|
|
|
$forcedownload = false |
|
) |
| |
|
static |
Factory method for creating of links to legacy course files.
- Parameters
-
int | $courseid | |
string | $filepath | |
bool | $forcedownload | |
- Return values
-
◆ make_pluginfile_url()
static moodle_url::make_pluginfile_url |
( |
|
$contextid, |
|
|
|
$component, |
|
|
|
$area, |
|
|
|
$itemid, |
|
|
|
$pathname, |
|
|
|
$filename, |
|
|
|
$forcedownload = false , |
|
|
|
$includetoken = false |
|
) |
| |
|
static |
Factory method for creation of url pointing to plugin file.
Please note this method can be used only from the plugins to create urls of own files, it must not be used outside of plugins!
- Parameters
-
int | $contextid | |
string | $component | |
string | $area | |
int | $itemid | |
string | $pathname | |
string | $filename | |
bool | $forcedownload | |
mixed | $includetoken | Whether to use a user token when displaying this group image. True indicates to generate a token for current user, and integer value indicates to generate a token for the user whose id is the value indicated. If the group picture is included in an e-mail or some other location where the audience is a specific user who will not be logged in when viewing, then we use a token to authenticate the user. |
- Return values
-
◆ make_webservice_pluginfile_url()
static moodle_url::make_webservice_pluginfile_url |
( |
|
$contextid, |
|
|
|
$component, |
|
|
|
$area, |
|
|
|
$itemid, |
|
|
|
$pathname, |
|
|
|
$filename, |
|
|
|
$forcedownload = false |
|
) |
| |
|
static |
Factory method for creation of url pointing to plugin file.
This method is the same that make_pluginfile_url but pointing to the webservice pluginfile.php script. It should be used only in external functions.
- Since
- 2.8
- Parameters
-
int | $contextid | |
string | $component | |
string | $area | |
int | $itemid | |
string | $pathname | |
string | $filename | |
bool | $forcedownload | |
- Return values
-
◆ merge_overrideparams()
moodle_url::merge_overrideparams |
( |
array |
$overrideparams = null | ) |
|
|
protected |
Merges parameters and validates them.
- Parameters
-
- Return values
-
- Exceptions
-
◆ out()
moodle_url::out |
( |
|
$escaped = true , |
|
|
array |
$overrideparams = null |
|
) |
| |
Output url.
If you use the returned URL in HTML code, you want the escaped ampersands. If you use the returned URL in HTTP headers, you want $escaped=false.
- Parameters
-
bool | $escaped | Use & as params separator instead of plain & |
array | $overrideparams | params to add to the output url, these override existing ones with the same name. |
- Return values
-
◆ out_as_local_url()
moodle_url::out_as_local_url |
( |
|
$escaped = true , |
|
|
array |
$overrideparams = null |
|
) |
| |
Returns URL a relative path from $CFG->wwwroot.
Can be used for passing around urls with the wwwroot stripped
- Parameters
-
boolean | $escaped | Use & as params separator instead of plain & |
array | $overrideparams | params to add to the output url, these override existing ones with the same name. |
- Return values
-
- Exceptions
-
◆ out_omit_querystring()
moodle_url::out_omit_querystring |
( |
|
$includeanchor = false | ) |
|
Returns url without parameters, everything before '?'.
- Parameters
-
bool | $includeanchor | if self::anchor is defined, should it be returned? |
- Return values
-
◆ param()
moodle_url::param |
( |
|
$paramname, |
|
|
|
$newvalue = '' |
|
) |
| |
Add a param to the params for this url.
The added param overrides existing one if they have the same name.
- Parameters
-
string | $paramname | name |
string | $newvalue | Param value. If new value specified current value is overriden or parameter is added |
- Return values
-
mixed | string parameter value, null if parameter does not exist |
◆ params()
moodle_url::params |
( |
array |
$params = null | ) |
|
Add an array of params to the params for this url.
The added params override existing ones if they have the same name.
- Parameters
-
array | $params | Defaults to null. If null then returns all params. |
- Return values
-
array | Array of Params for url. |
- Exceptions
-
◆ raw_out()
moodle_url::raw_out |
( |
|
$escaped = true , |
|
|
array |
$overrideparams = null |
|
) |
| |
Output url without any rewrites.
This is identical in signature and use to out() but doesn't call the rewrite handler.
- Parameters
-
bool | $escaped | Use & as params separator instead of plain & |
array | $overrideparams | params to add to the output url, these override existing ones with the same name. |
- Return values
-
◆ remove_all_params()
moodle_url::remove_all_params |
( |
|
$params = null | ) |
|
Remove all url parameters.
- Todo:
- remove the unused param.
- Parameters
-
- Return values
-
◆ remove_params()
moodle_url::remove_params |
( |
|
$params = null | ) |
|
Remove all params if no arguments passed.
Remove selected params if arguments are passed.
Can be called as either remove_params('param1', 'param2') or remove_params(array('param1', 'param2')).
- Parameters
-
string[] | string | $params,... | either an array of param names, or 1..n string params to remove as args. |
- Return values
-
◆ set_anchor()
moodle_url::set_anchor |
( |
|
$anchor | ) |
|
Sets the anchor for the URI (the bit after the hash)
- Parameters
-
string | $anchor | null means remove previous |
◆ set_scheme()
moodle_url::set_scheme |
( |
|
$scheme | ) |
|
Sets the scheme for the URI (the bit before ://)
- Parameters
-
◆ set_slashargument()
moodle_url::set_slashargument |
( |
|
$path, |
|
|
|
$parameter = 'file' , |
|
|
|
$supported = null |
|
) |
| |
Sets the url slashargument value.
- Parameters
-
string | $path | usually file path |
string | $parameter | name of page parameter if slasharguments not supported |
bool | $supported | usually null, then it depends on $CFG->slasharguments, use true or false for other servers |
- Return values
-
◆ $scheme
string moodle_url::$scheme = '' |
|
protected |
Scheme, ex.
: http, https
The documentation for this class was generated from the following file: