duandanbeng1829 2013-09-24 19:40
浏览 59
已采纳

Laravel返回Response :: view

Simple question, I think.

I have a route that calls a function in a controller. In that controller, I have a call to another controller function.

For example:

$_testing = with(new TestingController)->prepwork($variable1,$variable2);

Inside of TestingController prepwork(), if a condition matches, I

return Response::view(...);

Question - how come that isn't enough? the return just returns control back to the calling function (which makes sense), but how do I tell Laravel - stop what you are doing and output that view.

To make it work, I have to:

$_testing = with(new TestingController)->prepwork($variable1,$variable2);
return $_testing;

That doesn't really work as the prepwork is designed to do some heavy lifting and then output a result model. The view is only kicked off when there is an error.

And YES - I know I can do something like this:

if ($_testing->whatImCheckingForErrors) { return Response::view(...); }

I'm just trying to understand why the return Response::view doesn't end the processing... If that makes sense.

  • 写回答

1条回答 默认 最新

  • douhezhang8932 2013-09-24 20:13
    关注

    Only the very last return will end processing, because the application will receive this last return and render whatever you send in it.

    If you call a method (1), that calls another method (2), that calls a third one (3), Laravel app will receive the View only when your return back from (1).

    That's why when you added that last return it worked.

    There are things you can do, like:

    echo Response::view(...);
    die;
    

    It may work sometimes, but

    BUT THIS IS REALLY BAD, DO NOT DO THIS UNLESS YOU'RE JUST TESTING THINGS!

    Because Laravel won't be able to close everything and flush whatever it needs to and you can compromise your application and even server.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题