我在kohana写了一个样本控制器
<?php
defined('SYSPATH') OR die('No direct access allowed.');
class Controller_Album extends Controller {
public function action_index() {
$content=$this->request->param('id','value is null');
$this->response->body($content);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我试图点击url http:// localhost/k/album?id = 4时 我得到NULL值.如何使用request-> param访问kohana中的请求变量,而不使用$ _GET和$ _POST方法?
bia*_*ron 24
在Kohana的V3.1 +请求类有query()和post()方法.他们兼作getter和setter:
// get $_POST data
$data = $this->request->post();
// returns $_GET['foo'] or NULL if not exists
$foo = $this->request->query('foo');
// set $_POST['foo'] value for the executing request
$request->post('foo', 'bar');
// or put array of vars. All existing data will be deleted!
$request->query(array('foo' => 'bar'));
Run Code Online (Sandbox Code Playgroud)
但请记住,设置GET/POST数据不会使当前$ _GET/$ _ POST值超载.它们将在请求执行($request->execute()调用)后发送.