获取请求参数
参数绑定
Document控制器show方法
<?php
namespace app\web\controller;
use Timo\Core\Controller;
Class Document extends Controller
{
public function show($id = 0)
{
echo $id;
}
}
URL: http://www.timophp.com/document/show/100/
访问上面的URL,会打印出100,就相当于把url中show后面的100绑定到了show方法的$id参数上面,参数名称自定义
获取GET请求参数
get(参数名, [默认值], [过滤函数]);
例子:http://www.timophp.com/document/show/100/?type=1&from=index
$type = Request::get('type');
$type = Request::get('type', 0);
$type = Request::get('type', 0, 'intval');
getInt(参数名, [默认值]);
默认值可不传,默认为0,等价于Request::get(参数名, 0, 'interval')
Request::getInt('type')
getString(参数名, [默认值]);
默认值可不传,默认为空字符串,等价于Request::get(参数名, '', 'trim')
Request::getString('name')
获取POST请求参数
Request::post(参数名, [默认值], [过滤函数]);
Request::postInt(参数名, [默认值]);
Request::postString(参数名, [默认值]);
例子:
<form action="http://www.timophp.com/document/show/100/" method="POST">
<input type="text" name="email" />
<input type="text" name="password" />
<input type="submit" value="提交" />
</form>
$type = Request::post('email');
$type = Request::post('email', '');
$type = Request::post('password', '', 'trim');