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 欧拉系统opt目录空间使用100%
  • ¥15 ul做导航栏格式不对怎么改?
  • ¥20 用户端如何上传图片到服务器和数据库里
  • ¥15 现在研究生在烦开题,看了一些文献,但不知道自己要做什么,求指导。
  • ¥30 vivado封装时总是显示缺少一个dcp文件
  • ¥100 pxe uefi启动 tinycore
  • ¥15 我pycharm运行jupyter时出现Jupyter server process exited with code 1,然后打开cmd显示如下
  • ¥15 可否使用carsim-simulink进行四轮独立转向汽车的联合仿真,实现四轮独立转向汽车原地旋转、斜向形式、横移等动作,如果可以的话在carsim中如何进行相应设置
  • ¥15 Caché 2016 在Java环境通过jdbc 执行sql报Parameter list mismatch错误,但是同样的sql使用连接工具可以查询出数据
  • ¥15 疾病的获得与年龄是否有关