Laravel从私有方法重定向 [英] Laravel redirection from private method

查看:67
本文介绍了Laravel从私有方法重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有方法的控制器.该方法中的代码太长了,因此我将一些代码放在了其他私有方法中,以使这些方法变得可以理解并且不会弄乱它.

I have a controller that has a method. The code is too long in the method, so I have put some of the codes in other private methods, so that methods become understandable and not make a mess out of it.

现在,当我从URL访问公共方法时,根据参数,它将调用特定的私有方法来处理作业.处理完作业后,我想重定向到URL,但是重定向不起作用.

Now, when I access the public method from the URL, depending on parameters, it will call a specific private method to process the job. After the job is processed, I want to redirect to a URL, but the redirection is not working.

我的代码示例如下:

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');
    }
}

问题是,以上重定向不起作用.这是为什么?在Codeigniter中,当您使用redirect时,它在调用它的地方起作用.

The problem is, the above redirect does not work. Why is that? In Codeigniter, when you used redirect it works nomatter where it is called from.

如果上述代码示例不是正确的执行方法,那么如果有人可以向我展示如何完成此操作,将不胜感激.谢谢.

If the above code sample is not the right way to do it, would appreciate if someone could show me how it is to be done. Thanks.

推荐答案

您也必须从$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');
  }
}

这篇关于Laravel从私有方法重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆