Web*_*ice 8 php laravel laravel-4
我有一个控制器,有一个方法.代码在方法中太长了,所以我把一些代码放在其他私有方法中,这样方法就变得可以理解,而不会弄乱它.
现在,当我从URL访问公共方法时,根据参数,它将调用特定的私有方法来处理作业.处理作业后,我想重定向到URL,但重定向不起作用.
我的代码示例如下:
class SomeClass extends BaseController{
public function getMethodName()
{
//check the params and choose a private method to call
$this->processJob();
}
private function processJob()
{
//process the job and redirect at the end
return Redirect::to('some/url');
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,上面的重定向不起作用.这是为什么?在Codeigniter中,当你使用redirect
它时,它可以在调用它的地方工作.
如果上面的代码示例不是正确的方法,那么如果有人能告诉我如何完成它,我将不胜感激.谢谢.
小智 15
你也必须退回$this->processJob()
.
class SomeClass extends BaseController{
public function getMethodName()
{
//check the params and choose a private method to call
return $this->processJob();
}
private function processJob()
{
//process the job and redirect at the end
return Redirect::to('some/url');
}
}
Run Code Online (Sandbox Code Playgroud)