在 Kohana/PHP 中,如何将执行发送到新的控制器/操作?

发布于 2024-10-12 15:46:12 字数 872 浏览 7 评论 0原文

在 PHP/Kohana 中,我有控制器操作方法来进行一些处理。完成后,我想将其发送到另一个控制器,例如:

public function action_import_csv()
{
    Kohana_Import_Driver_Csv::process_files_from_csv_to_mysql($this->import_directory);
    //url::redirect(Route::get('backend_application')->uri()); //undefined method URL::redirect()
    //redirect(Route::get('backend_application')->uri(), null); //undefined function
}

根据 此文档至少第一个重定向应该有效。我正在使用 Kohana 3

如何将执行从此控制器操作方法发送到新的控制器/操作?

附录

由于某种原因,url::redirect 不可用,以下是我为 url 获得的代码完成: ::

alt text

@bharath,我尝试了 url::current()并收到此错误:

alt text

In PHP/Kohana, I have controller action method which does some processing. When it is finished, I want to send it to another controller, e.g.:

public function action_import_csv()
{
    Kohana_Import_Driver_Csv::process_files_from_csv_to_mysql($this->import_directory);
    //url::redirect(Route::get('backend_application')->uri()); //undefined method URL::redirect()
    //redirect(Route::get('backend_application')->uri(), null); //undefined function
}

According to this documentation at least the first redirect should work. I'm using Kohana 3.

How can I send execution from this controller action method to a new controller/action?

Addendum

For some reason, url::redirect is not available, here is the code completion I get for url:::

alt text

@bharath, I tried url::current() and got this error:

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

物价感观 2024-10-19 15:46:12

问题是您正在查看 Kohana 2 文档。转到 kohana 主页并找到正确的文档。另外,由于某种原因,每个人都给你 Kohana 2 答案,即使你说你正在使用 3。

要重定向,请从控制器的上下文中执行此操作:
$this->request->redirect($something);

$something 可以是:

controller
controller/action
http://url.com

这里redirect方法的api文档(请注意,这使用url::site来解析url; 您可能还想查看该方法的来源。

The problem is that you are looking at the Kohana 2 docs. Go to the kohana homepage and find the correct docs. Also, for some reason, everyone is giving you Kohana 2 answers even though you stated you're working with 3.

To redirect, do this from the context of a controller:
$this->request->redirect($something);

$something could be:

controller
controller/action
http://url.com

Here are the api docs for the redirect method (note that this uses url::site to parse the url; you may want to look at the source of that method too.

以往的大感动 2024-10-19 15:46:12

我不太确定,但我认为您可以简单地使用 redirect() 函数传递您想要发送到的其他控制器以及任何参数

示例

redirect(controllername/method)

i am not very sure but i think you can simple use the redirect() function passing in the other controller you want to send to with any parameters

example

redirect(controllername/method)
白日梦 2024-10-19 15:46:12

不应该是这样吗:

url::redirect('controller/method');

如果它不起作用,您可能在调用重定向之前有一些输出(在这种情况下,您可能会收到“标头已发送”错误)。

Shouldn't that be :

url::redirect('controller/method');

And if it doesn't work, you probably had some output before calling the redirect (you'll probably get the "Headers already sent" error when that is the case).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文