MDL-15813 "return params or a param from moodle_url params and param method when no value is passed to method to set url param(s)."

Methods param and params can now be used in the following ways :

$url->params(); // returns params

$url->params($arrayofnewparams);// add params to url params and then returns all the params.

//--

$url->param('id');//returns value of id param.

$url->param('id', 5); set id param to 5.
This commit is contained in:
jamiesensei
2008-07-24 15:22:31 +00:00
parent 876c7b831e
commit c1f41c59b7
+17 -6
View File
@@ -342,10 +342,16 @@ class moodle_url {
* Add an array of params to the params for this page. The added params override existing ones if they
* have the same name.
*
* @param array $params
* @param array $params Defaults to null. If null then return value of
* param 'name'.
* @return array params for url.
*/
function params($params){
$this->params = $params + $this->params;
function params($params = null){
if (!is_null($params)){
return $this->params = $params + $this->params;
} else {
return $this->params;
}
}
/**
@@ -372,10 +378,15 @@ class moodle_url {
* have the same name.
*
* @param string $paramname name
* @param string $param value
* @param string $param value. Defaults to null. If null then return value
* of param 'name'
*/
function param($paramname, $param){
$this->params = array($paramname => $param) + $this->params;
function param($paramname, $param = null){
if (!is_null($param)){
$this->params = array($paramname => $param) + $this->params;
} else {
$this->params[$paramname];
}
}