【问题标题】:$this->request->param() and $this->request->post() in kohana 3.2kohana 3.2 中的 $this->request->param() 和 $this->request->post()
【发布时间】:2013-07-02 05:24:49
【问题描述】:

kohana 3.2 中$this->request->param() 和$this->request->post() 有什么区别?

有人简单解释一下。

谢谢

【问题讨论】:

  • params 包括 get 和 post,而 post 只包括 post 变量

标签: php mysql kohana kohana-3


【解决方案1】:

假设你有这样的 URL:http://example.com/store/books/computer/martin_fowler 路由定义如下:

Route::set('books', '<controller>/<action>(/<product>(/<category>(/<author>)))')
        ->defaults(array(
            'controller' => 'store',
            'action' => '',
        ));

$this-&gt;request-&gt;param() 这将返回:

array (
  'product' => 'books', 
  'category' => 'computer',
  'author' => 'martin_fowler',
)

$this-&gt;request-&gt;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

【讨论】:

  • 感谢您提供的信息 matino。我了解 $this->request->param() 和 $this->request->post() 是如何工作的。
【解决方案2】:

在科哈纳

$data = $this->request->post();
// get $_POST data

返回 post 数据,如提交表单。

$this->request->param()

返回发布的数据以及从 $_POST 和 $_GET 发送的数据。

【讨论】:

    【解决方案3】:

    Param 在路由过程之后获取分配给请求的请求参数,而 post 获取原始数据 POST。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多