Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250711) (9addea9f0ac)
|
Public Member Functions | |
__construct ( $url, ?array $params=null, $anchor=null,) | |
Create new instance of url. | |
__toString () | |
Shortcut for printing of encoded URL. | |
compare (self $url, $matchtype=URL_MATCH_EXACT) | |
Compares this 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. | |
get_slashargument () | |
Returns the 'slashargument' 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 ($unused=null) | |
Remove all url parameters. | |
remove_params (... $params) | |
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 | from_uri (UriInterface $uri) |
Create a new url instance from a UriInterface. | |
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. | |
static | routed_path (string $path, ?array $params=null, ?string $anchor=null,) |
Create a new moodle_url instance from routed path. | |
Protected Member Functions | |
merge_overrideparams (?array $overrideparams=null) | |
Merges parameters. | |
core\url::__construct | ( | $url, | |
?array | $params = null, | ||
$anchor = null ) |
Create new instance of url.
self | 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. |
null | 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 |
core\url::__toString | ( | ) |
Shortcut for printing of encoded URL.
string |
core\url::compare | ( | self | $url, |
$matchtype = URL_MATCH_EXACT ) |
Compares this url with another.
See documentation of constants for an explanation of the comparison flags.
self | $url | The moodle_url object to compare |
int | $matchtype | The type of comparison (URL_MATCH_BASE, URL_MATCH_PARAMS, URL_MATCH_EXACT) |
bool |
core\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. |
|
static |
Create a new url instance from a UriInterface.
UriInterface | $uri |
self |
core\url::get_encoded_anchor | ( | ) |
Encode the anchor according to RFC 3986.
string | The encoded anchor |
core\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. |
core\url::get_param | ( | $name | ) |
Returns a given parameter value from the URL.
string | $name | Name of parameter |
array|string|null | Value of parameter or null if not set. |
core\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 |
core\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. |
core\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 & |
null | 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. |
core\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. |
core\url::get_slashargument | ( | ) |
Returns the 'slashargument' portion of a URL.
For example, if the URL is http://www.example.org.com/pluginfile.php/1/core_admin/logocompact/ then this will return '1/core_admin/logocompact/'.
string | Slash argument as string. |
core\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 |
url |
|
static |
General moodle file url.
string | $urlbase | the script serving the file |
string | $path | |
bool | $forcedownload |
self |
|
static |
Factory method for creating of links to legacy course files.
int | $courseid | |
string | $filepath | |
bool | $forcedownload |
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. |
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 |
url |
|
protected |
Merges parameters.
null | array | $overrideparams |
array | merged parameters |
core\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 & |
null | array | $overrideparams | params to add to the output url, these override existing ones with the same name. |
string | Resulting URL |
core\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 |
core\url::out_omit_querystring | ( | $includeanchor = false | ) |
Returns url without parameters, everything before '?
'.
bool | $includeanchor | if { |
string |
core\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 |
array|string|null | parameter value, null if parameter does not exist. |
core\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.
null | array | $params | Array of parameters to add. Note all values that are not arrays are cast to strings. |
array | Array of Params for url. |
coding_exception |
core\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 & |
null | array | $overrideparams | params to add to the output url, these override existing ones with the same name. |
string | Resulting URL |
core\url::remove_all_params | ( | $unused = null | ) |
Remove all url parameters.
array | $unused | Unused param |
core\url::remove_params | ( | ... | ) |
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 |
|
static |
Create a new moodle_url instance from routed path.
string | $path | The routed path |
null | array | $params | The path parameters |
null | string | $anchor | The anchor |
self |
core\url::set_anchor | ( | $anchor | ) |
Sets the anchor for the URI (the bit after the hash)
string | $anchor | null means remove previous |
core\url::set_scheme | ( | $scheme | ) |
Sets the scheme for the URI (the bit before ://)
string | $scheme |
core\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 |