Laravel 4.2 - 路线不断失败

时间:2015-01-15 02:48:36

标签: laravel-4 routing

我有一个应用程序,当我的用户注销或登录会话到期时,由于某种原因重定向到登录页面仍然失败..我一直在搜索,但我对解决方案视而不见。有人可以看看这个并发现我的问题吗?

我有一个用户登录路线:

    /*
    | Sign in (GET)
    */
    Route::get('/account/sign-in', array(
        'as' => 'account-sign-in',
        'uses' => 'AccountController@getSignIn'
    ));

getSignIn只是组装一个视图:

public function getSignIn() {
    return View::make('account.signin');
}

我也有经过身份验证的组路线

/*
| Authenticated group
*/
Route::group(array('before' => 'auth'), function() {

    Route::group(array('prefix' => 'admin'), function()
    {
        Route::get('/languages', array(
            'as' => 'language-list',
            'uses' => 'LanguageController@getLanguages'
        ));
    });
}

getLanguages就像这样:

public function getLanguages() {

    if( Auth::check()) {

        $languages = Language::all();

        return  View::make('admin.language')->with('languages', $languages);

    } else {

        return Redirect::route('account-sign-in');
    }
}

看起来每次执行此行都会导致重定向失败

return Redirect::route('account-sign-in');

我收到此错误:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException



11. Symfony\Component\HttpKernel\Exception\NotFoundHttpException
…\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php148 

1 个答案:

答案 0 :(得分:1)

此:

public function getSignIn() {
    return View::make('account.signin');
}

应该是:

public function getSign_in() {
    return View::make('account.signin');
}

<强>解释

来自Illuminate API:ControllerInspector.php

/**
 * Determine the URI from the given method name.
 *
 * @param  string  $name
 * @param  string  $prefix
 * @return string
 */
public function getPlainUri($name, $prefix)
{
    return $prefix.'/'.implode('-', array_slice(explode('_', snake_case($name)), 1));
}

鉴于laravel使用snake_case查找控制器方法,AccountController@getSignIn Route参数中的uses方法名称将转换为 snake case getSign_in()