-
Notifications
You must be signed in to change notification settings - Fork 115
Dev.Module Parameters
How to read parameters
params
The params
plugin helps you to get current module, controller and action information or parameters post by GET method.
This plugin takes two parameters, the first parameter is a string describes the information want to fetch, it can be module
, controller
, action
or parameter name, and the second parameter is optional, it will be set as return value if there is no value searched according to first parameter.
For example, if you adding following code in module login
, controller index
and action index
such as:
echo $this->params('module');
echo $this->params('default', 'default');
Output:
'login'
'default'
Supposing you post data by query string like this: domain/url/login/login/param-default
, then you can use the following code to fetch the value default
:
$this->params('param');
If the url is: domain/url/login/login/param/default
, you should use the following API:
$this->params()->fromRoute('param');
If the url is: domain/url/login/login/?param=default
, the code should be replaced as:
$this->params()->fromQuery('param');
If you post parameters by POST method, you can use fromPost()
method:
$this->params()->fromPost('param');
getPost
If you post a form data, you can also use getPost method to fetch these data:
$posts = $this->request->getPost();
$name = $posts['name'];
In this example, the name
field is the form name value.
<input name="name" type="text" />
<select name="name"></select>