如何使用 Kohana 3 Request::factory 命令发送获取参数?

发布于 2024-10-29 22:58:21 字数 800 浏览 4 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

︶葆Ⅱㄣ 2024-11-05 22:58:21

对于 3.1,您可以使用 Request 类的 query() 方法:

equest::factory('/test/deliveryaddress?)->query('region_name', 'top')->execute();

对于 3.0,没有真正的隔离,您必须操作 $_GET数组。

For 3.1, you can use the query() method of the Request class:

equest::factory('/test/deliveryaddress?)->query('region_name', 'top')->execute();

For 3.0, there is no real isolation, and you have to manipulate the $_GET array.

眼眸里的那抹悲凉 2024-11-05 22:58:21

使用 Request 类和控制器中的 query()

而不是:

$region_name = isset($_GET['region_name']) ? $_GET['region_name'] : '';

尝试:

$get = $this->request->query();
$region_name = isset($get['region_name']) ? $get['region_name'] : '';

use query() from Request class and in your controller

instead of:

$region_name = isset($_GET['region_name']) ? $_GET['region_name'] : '';

try:

$get = $this->request->query();
$region_name = isset($get['region_name']) ? $get['region_name'] : '';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文