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

在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 2013-11-18 23:55
    关注

    Change this

     $this->doSomethingExtra();
    

    to this.

     return $this->doSomethingExtra();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面