【发布时间】:2013-07-02 05:24:49
【问题描述】:
kohana 3.2 中$this->request->param() 和$this->request->post() 有什么区别?
有人简单解释一下。
谢谢
【问题讨论】:
-
params 包括 get 和 post,而 post 只包括 post 变量
kohana 3.2 中$this->request->param() 和$this->request->post() 有什么区别?
有人简单解释一下。
谢谢
【问题讨论】:
假设你有这样的 URL:http://example.com/store/books/computer/martin_fowler 路由定义如下:
Route::set('books', '<controller>/<action>(/<product>(/<category>(/<author>)))')
->defaults(array(
'controller' => 'store',
'action' => '',
));
$this->request->param() 这将返回:
array (
'product' => 'books',
'category' => 'computer',
'author' => 'martin_fowler',
)
$this->request->post() 将返回 $_POST 数据。
如果找不到键,这两种方法都将返回 NULL:
$this->request->param('xxx') // NULL
$this->request->param('author') // martin_fowler
$this->request->post('id') // Some id value in $_POST or NULL if id doesn't exist in $_POST
【讨论】:
在科哈纳
$data = $this->request->post();
// get $_POST data
返回 post 数据,如提交表单。
$this->request->param()
返回发布的数据以及从 $_POST 和 $_GET 发送的数据。
【讨论】:
Param 在路由过程之后获取分配给请求的请求参数,而 post 获取原始数据 POST。
【讨论】: