[laravel]Symfony Redirect To Route Dispatch Request问题

网友投稿 688 2022-09-02

[laravel]Symfony Redirect To Route Dispatch Request问题

[laravel]Symfony Redirect To Route Dispatch Request问题

首先参考: ​​: ​​App\Http\Controllers;use Illuminate\Routing\Router;use App\Http\Controllers\Controller;use Illuminate\Http\Request as HttpRequest;class MyController extends Controller { public function __construct(HttpRequest $Router $router) { $this->middleware('auth', ['except' => ['action1', 'action2']]); $this->= $ $this->appRouter = $router; } //Route=my/need-forward (Create new request and dispatch) public function needForward() { // $route_name = action("MyController@forwardHere"); // $route_name = action("OtherFolder\MyController@forwardHere"); // $route_name = action("MyController@forwardHere", ["id" => 100, "name" => "Name Text", "roll" => 303]); $request = HttpRequest::create($route_name, 'GET', array("param1" => "Param 1", "param2" => "Param 2")); return app()->handle($request); } //Route=my/need-forward (Forward same request to new route) public function needForward2() { $route_name = "my/forward-here"; $request = HttpRequest::create($route_name); return $this->appRouter->dispatch($request); } //Route=my/forward-here public function forwardHere() { echo "Browse [/my/need-forward] will send output of [/my/forward-here]"; }}

观察以上代码,其实app()->handle($request)和$this->appRouter->dispatch($request)是主要区别

但是用dispatch则没有问题

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:剑指offer 面试题14
下一篇:PHP 多任务秒级定时器的实现方法(php菜鸟教程)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~