在 Kohana/PHP 中,如何将执行发送到新的控制器/操作?
在 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 获得的代码完成: :
:
@bharath,我尝试了 url::current()
并收到此错误:
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::
:
@bharath, I tried url::current()
and got this error:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是您正在查看 Kohana 2 文档。转到 kohana 主页并找到正确的文档。另外,由于某种原因,每个人都给你 Kohana 2 答案,即使你说你正在使用 3。
要重定向,请从控制器的上下文中执行此操作:
$this->request->redirect($something);
$something
可以是:这里是
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:Here are the api docs for the
redirect
method (note that this usesurl::site
to parse the url; you may want to look at the source of that method too.我不太确定,但我认为您可以简单地使用
redirect()
函数传递您想要发送到的其他控制器以及任何参数示例
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 parametersexample
不应该是这样吗:
如果它不起作用,您可能在调用重定向之前有一些输出(在这种情况下,您可能会收到“标头已发送”错误)。
Shouldn't that be :
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).