Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
|
Class for creating and manipulating urls. More...
Public Member Functions | |
__construct ($url, array $params=null, $anchor=null) | |
Create new instance of moodle_url. | |
__toString () | |
Shortcut for printing of encoded URL. | |
compare (moodle_url $url, $matchtype=URL_MATCH_EXACT) | |
Compares this moodle_url with another. | |
export_params_for_template () | |
Get the url params as an array of key => value pairs. | |
get_encoded_anchor () | |
Encode the anchor according to RFC 3986. | |
get_host () | |
Returns the 'host' portion of a URL. | |
get_param ($name) | |
Returns a given parameter value from the URL. | |
get_path ($includeslashargument=true) | |
Returns the 'path' portion of a URL. | |
get_port () | |
Returns the 'port' portion of a URL. | |
get_query_string ($escaped=true, array $overrideparams=null) | |
Get the params as as a query string. | |
get_scheme () | |
Returns the 'scheme' portion of a URL. | |
is_local_url () | |
Checks if URL is relative to $CFG->wwwroot. | |
out ($escaped=true, array $overrideparams=null) | |
Output url. | |
out_as_local_url ($escaped=true, array $overrideparams=null) | |
Returns URL as relative path from $CFG->wwwroot. | |
out_omit_querystring ($includeanchor=false) | |
Returns url without parameters, everything before '?'. | |
param ($paramname, $newvalue='') | |
Add a param to the params for this url. | |
params (array $params=null) | |
Add an array of params to the params for this url. | |
raw_out ($escaped=true, array $overrideparams=null) | |
Output url without any rewrites. | |
remove_all_params ($params=null) | |
Remove all url parameters. | |
remove_params ($params=null) | |
Remove all params if no arguments passed. | |
set_anchor ($anchor) | |
Sets the anchor for the URI (the bit after the hash) | |
set_scheme ($scheme) | |
Sets the scheme for the URI (the bit before ://) | |
set_slashargument ($path, $parameter='file', $supported=null) | |
Sets the url slashargument value. | |
Static Public Member Functions | |
static | make_draftfile_url ($draftid, $pathname, $filename, $forcedownload=false) |
Factory method for creation of url pointing to draft file of current user. | |
static | make_file_url ($urlbase, $path, $forcedownload=false) |
General moodle file url. | |
static | make_legacyfile_url ($courseid, $filepath, $forcedownload=false) |
Factory method for creating of links to legacy course files. | |
static | make_pluginfile_url ($contextid, $component, $area, $itemid, $pathname, $filename, $forcedownload=false, $includetoken=false) |
Factory method for creation of url pointing to plugin file. | |
static | make_webservice_pluginfile_url ($contextid, $component, $area, $itemid, $pathname, $filename, $forcedownload=false) |
Factory method for creation of url pointing to plugin file. | |
Protected Member Functions | |
merge_overrideparams (array $overrideparams=null) | |
Merges parameters and validates them. | |
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
moodle_url::__construct | ( | $url, | |
array | $params = null, | ||
$anchor = null ) |
Create new instance of moodle_url.
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. |
moodle_exception |
moodle_url::__toString | ( | ) |
Shortcut for printing of encoded URL.
string |
moodle_url::compare | ( | moodle_url | $url, |
$matchtype = URL_MATCH_EXACT ) |
Compares this moodle_url with another.
See documentation of constants for an explanation of the comparison flags.
moodle_url | $url | The moodle_url object to compare |
int | $matchtype | The type of comparison (URL_MATCH_BASE, URL_MATCH_PARAMS, URL_MATCH_EXACT) |
bool |
moodle_url::export_params_for_template | ( | ) |
Get the url params as an array of key => value pairs.
This helps in handling cases where url params contain arrays.
array | params array for templates. |
moodle_url::get_encoded_anchor | ( | ) |
Encode the anchor according to RFC 3986.
string | The encoded anchor |
moodle_url::get_host | ( | ) |
Returns the 'host' 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 'www.example.org'.
string | Host of the URL. |
moodle_url::get_param | ( | $name | ) |
Returns a given parameter value from the URL.
string | $name | Name of parameter |
string | Value of parameter or null if not set |
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.)
bool | $includeslashargument | If true, includes slash arguments |
string | Path of URL |
moodle_url::get_port | ( | ) |
Returns the 'port' 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 '447'.
string | Port of the URL. |
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.
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. |
string | query string that can be added to a url. |
moodle_url::get_scheme | ( | ) |
Returns the 'scheme' 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 'http' (without the colon).
string | Scheme of the URL. |
moodle_url::is_local_url | ( | ) |
Checks if URL is relative to $CFG->wwwroot.
bool | True if URL is relative to $CFG->wwwroot; otherwise, false. |
|
static |
Factory method for creation of url pointing to draft file of current user.
int | $draftid | draft item id |
string | $pathname | |
string | $filename | |
bool | $forcedownload |
moodle_url |
|
static |
General moodle file url.
string | $urlbase | the script serving the file |
string | $path | |
bool | $forcedownload |
moodle_url |
|
static |
Factory method for creating of links to legacy course files.
int | $courseid | |
string | $filepath | |
bool | $forcedownload |
moodle_url |
|
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!
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. |
moodle_url |
|
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.
int | $contextid | |
string | $component | |
string | $area | |
int | $itemid | |
string | $pathname | |
string | $filename | |
bool | $forcedownload |
moodle_url |
|
protected |
Merges parameters and validates them.
array | $overrideparams |
array | merged parameters |
coding_exception |
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.
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. |
string | Resulting URL |
moodle_url::out_as_local_url | ( | $escaped = true, | |
array | $overrideparams = null ) |
Returns URL as relative path from $CFG->wwwroot.
Can be used for passing around urls with the wwwroot stripped
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. |
string | Resulting URL |
coding_exception | if called on a non-local url |
moodle_url::out_omit_querystring | ( | $includeanchor = false | ) |
Returns url without parameters, everything before '?'.
bool | $includeanchor | if self::anchor is defined, should it be returned? |
string |
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.
string | $paramname | name |
string | $newvalue | Param value. If new value specified current value is overriden or parameter is added |
mixed | string parameter value, null if parameter does not exist |
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.
array | $params | Defaults to null. If null then returns all params. |
array | Array of Params for url. |
coding_exception |
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.
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. |
string | Resulting URL |
moodle_url::remove_all_params | ( | $params = null | ) |
Remove all url parameters.
array | $params | Unused param |
void |
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')).
string[] | string | $params,... | either an array of param names, or 1..n string params to remove as args. |
array | url parameters |
moodle_url::set_anchor | ( | $anchor | ) |
Sets the anchor for the URI (the bit after the hash)
string | $anchor | null means remove previous |
moodle_url::set_scheme | ( | $scheme | ) |
Sets the scheme for the URI (the bit before ://)
string | $scheme |
moodle_url::set_slashargument | ( | $path, | |
$parameter = 'file', | |||
$supported = null ) |
Sets the url slashargument value.
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 |
void |