为什么Laravel "remembering"这条被删除的路由?
Why is Laravel "remembering" this deleted route?
我有一个 route > controller > view
组合,它在 Laravel 中显示了一个登录表单。
表单不再需要,所以我干脆删除了如下所示的代码。
// file: routes.php
Route::get('/account/sign-in', array(
'as' => 'account-sign-in',
'uses' => 'AccountController@getSignIn'
));
.
// file: AccountController.php
public function getSignIn() {
return View::make('account.signin');
}
.
// file: /app/views/account/signin.blade.php
如果我在浏览器地址栏中输入旧的 URL: /account/sign-in
我会得到 Laravels "whoops" 屏幕:
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
* @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
protected function methodNotAllowed(array $others)
{
throw new MethodNotAllowedHttpException($others);
}
如何防止请求旧路由时抛出此异常?
相关信息
- Laravel版本:v4.2.5
- 如果我输入任何其他路由 "unknown" 到 Laravel - 它会被
App::missing();
路由捕获并重定向 - 带有 "user friendly" 消息
- 以
/account
开头的路线列表(还有更多,为简洁起见减少了列表)
POST account/change-password
GET|HEAD account/change-password
account/sign-out
POST account/forgot-password
POST account/create
POST account/sign-in
GET|HEAD account/forgot-password
我已经尝试过
- 作曲家转储自动加载
什么都不记得了。
它向您显示 404 错误页面,因为路由不存在。您可以通过异常看到:MethodNotAllowedHttpException
原因是你有Route::post('account/sign-in')
.
如果您不想为该路由显示 404 错误页面 - 您需要保留 Route::get() - 然后从控制器重定向(使用 return Redirect::*
)到另一个页面 - 所以用户会自动重定向。
或者您需要将 Route::post('account/sign-in')
更改为其他内容。
我有一个 route > controller > view
组合,它在 Laravel 中显示了一个登录表单。
表单不再需要,所以我干脆删除了如下所示的代码。
// file: routes.php
Route::get('/account/sign-in', array(
'as' => 'account-sign-in',
'uses' => 'AccountController@getSignIn'
));
.
// file: AccountController.php
public function getSignIn() {
return View::make('account.signin');
}
.
// file: /app/views/account/signin.blade.php
如果我在浏览器地址栏中输入旧的 URL: /account/sign-in
我会得到 Laravels "whoops" 屏幕:
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
* @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
protected function methodNotAllowed(array $others)
{
throw new MethodNotAllowedHttpException($others);
}
如何防止请求旧路由时抛出此异常?
相关信息
- Laravel版本:v4.2.5
- 如果我输入任何其他路由 "unknown" 到 Laravel - 它会被
App::missing();
路由捕获并重定向 - 带有 "user friendly" 消息 - 以
/account
开头的路线列表(还有更多,为简洁起见减少了列表)
POST account/change-password
GET|HEAD account/change-password
account/sign-out
POST account/forgot-password
POST account/create
POST account/sign-in
GET|HEAD account/forgot-password
我已经尝试过
- 作曲家转储自动加载
什么都不记得了。
它向您显示 404 错误页面,因为路由不存在。您可以通过异常看到:MethodNotAllowedHttpException
原因是你有Route::post('account/sign-in')
.
如果您不想为该路由显示 404 错误页面 - 您需要保留 Route::get() - 然后从控制器重定向(使用 return Redirect::*
)到另一个页面 - 所以用户会自动重定向。
或者您需要将 Route::post('account/sign-in')
更改为其他内容。