如何使用 Kohana 3 Request::factory 命令发送获取参数?
我有一个 Kohana 3 MVC 应用程序。
在视图中,我可以使用此行显式调用控制器的操作:
Request::factory('/test/deliveryaddress')->execute();
但我还想向该操作发送一个参数以进行如下处理:
public function action_deliveryaddress($region_name = NULL)
{
$view = new View('test/deliveryaddress');
$region_name = isset($_GET['region_name']) ? $_GET['region_name'] : '';
$view->set('region_name', $region_name);
$this->request->response = $view;
}
我已经尝试了这两种尝试,但它们不起作用:
Request::factory('/test/deliveryaddress?region_name=top')->execute(); //error
Request::factory('/test/deliveryaddress', array('region_name'=>'top'))->execute(); //ignored
如何使用 Request::factory() 发送 GET 变量,或者是否有更好的方法将 GET 参数发送到操作?
I have a Kohana 3 MVC application.
In a view, I can explicitly call a controller's action with this line:
Request::factory('/test/deliveryaddress')->execute();
But I want to also send a parameter to the action as well to be processed like this:
public function action_deliveryaddress($region_name = NULL)
{
$view = new View('test/deliveryaddress');
$region_name = isset($_GET['region_name']) ? $_GET['region_name'] : '';
$view->set('region_name', $region_name);
$this->request->response = $view;
}
I've tried these two attempts but they don't work:
Request::factory('/test/deliveryaddress?region_name=top')->execute(); //error
Request::factory('/test/deliveryaddress', array('region_name'=>'top'))->execute(); //ignored
How can I send a GET variable with Request::factory() or is there a better way to send GET parameters to an action?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 3.1,您可以使用
Request
类的query()
方法:对于 3.0,没有真正的隔离,您必须操作
$_GET数组。
For 3.1, you can use the
query()
method of theRequest
class:For 3.0, there is no real isolation, and you have to manipulate the
$_GET
array.使用 Request 类和控制器中的 query()
而不是:
尝试:
use query() from Request class and in your controller
instead of:
try: