drtkyykai004574380
drtkyykai004574380
2013-11-18 23:51
浏览 170
已采纳

在laravel中调用其他控制器方法

I'm relatively new to the laravel framework and i noticed a pretty disturbing issue with laravel controllers. I dont know if its me but it doesnt seem to work at all. Lets say i have a controller and i want to split the logic contained in the method called when the request hits a route tied to the controller.

class SomeController extends BaseController
{
    function doSomething()
    {
        $this->doSomethingExtra();
    }

    function doSomethingExtra()
    {
        return "Something Extra Done";
    }
}

And lets say a have to route defined like so

Route::get('main/dashboard','SomeController@doSomething');

the second method called from the first never returns the string "Something Extra Done" to the browser. infact it returns an empty 200 response. However this seems to work when you return response from the doSomething() as usual. Anyone know why this is behaving this way? is there anyway to breakup a controller logic into several Methods that actually return responses to the client?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxing8855
    douxing8855 2013-11-18 23:55
    已采纳

    Change this

     $this->doSomethingExtra();
    

    to this.

     return $this->doSomethingExtra();
    
    点赞 评论

相关推荐