Laravel 4:使用Route :: resources的RouteNotFoundException

时间:2013-04-12 11:09:54

标签: php laravel laravel-4

登录成功后尝试访问localhost:8000 / users时出现以下错误:

    RouteNotFoundException: Unable to generate a URL for the named route "users" as 
    such route does not exist.

我的控制器是:

<?php

class UserController extends BaseController {

    //public $restful = TRUE;

    public function index()
    {
        return View::make('users.index')
            ->with('title', "Title Example")
            ->with('users', User::all());
    }


    public function create()
    {
        return View::make('users.new')
            ->with('title', "New User");
    }

    ...

我的routes.php:

Route::resource('users', 'UserController');

Route::get('login', array( 'as' =>'login','uses' => 'UserController@login'));

Route::post('login', function(){

    $credentials = array('email' => Input::get('email'), 'password' => Input::get('password'));

    if (Auth::attempt($credentials))
    {
         return Redirect::route('users.index');
    }
    else
    {
        return Redirect::back()->withInput()->with('login_errors',true);;
    }   

});

Route::get('logout', function(){

        Auth::logout();

        return Redirect::route('login');
});

控制台php工匠路线

GET /                                                   Closure                         
GET /users                       users.index            UserController@index            
GET /users/create                users.create           UserController@create           
POST /users                      users.store            UserController@store            
GET /users/{users}               users.show             UserController@show             
GET /users/{users}/edit          users.edit             UserController@edit             
PUT /users/{users}               users.update           UserController@update           
PATCH /users/{users}                                    UserController@update           
DELETE /users/{users}            users.destroy          UserController@destroy          
GET /login                       login                  UserController@login            
POST /login                                             Closure                         
GET /logout                                             Closure   

例外:

in /Users/sangar1982/Sites/tlaravel4/vendor/symfony/routing/Symfony/Component/Routing/Generator/UrlGenerator.php line 134
at UrlGenerator->generate('users', array(), true) in /Users/sangar1982/Sites/tlaravel4/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php line 181
at UrlGenerator->route('users') in /Users/sangar1982/Sites/tlaravel4/bootstrap/compiled.php line 4299
at Facade::__callStatic('route', array('users')) in /Users/sangar1982/Sites/tlaravel4/app/storage/views/5fc6ba4595a2ad28f9c15b73141f869f line 30
at URL::route('users') in /Users/sangar1982/Sites/tlaravel4/app/storage/views/5fc6ba4595a2ad28f9c15b73141f869f line 30
at include('/Users/sangar1982/Sites/tlaravel4/app/storage/views/5fc6ba4595a2ad28f9c15b73141f869f') in /Users/sangar1982/Sites/tlaravel4/bootstrap/compiled.php line 15928
at PhpEngine->evaluatePath('/Users/sangar1982/Sites/tlaravel4/bootstrap/../app/storage/views/5fc6ba4595a2ad28f9c15b73141f869f', array('__env' => object(Environment), 'app' => object(Application), 'errors' => object(MessageBag), 'title' => 'Title Example', 'users' => object(Collection))) in /Users/sangar1982/Sites/tlaravel4/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php line 45
at CompilerEngine->get('/Users/sangar1982/Sites/tlaravel4/app/config/../views/layouts/backend.blade.php', array('__env' => object(Environment), 'app' => object(Application), 'errors' => object(MessageBag), 'title' => 'Title Example', 'users' => object(Collection))) in /Users/sangar1982/Sites/tlaravel4/bootstrap/compiled.php line 15692
at View->getContents() in /Users/sangar1982/Sites/tlaravel4/bootstrap/compiled.php line 15675
at View->render() in /Users/sangar1982/Sites/tlaravel4/app/storage/views/178250f445fac7ac6adce8b5af153a21 line 8
at include('/Users/sangar1982/Sites/tlaravel4/app/storage/views/178250f445fac7ac6adce8b5af153a21') in /Users/sangar1982/Sites/tlaravel4/bootstrap/compiled.php line 15928
at PhpEngine->evaluatePath('/Users/sangar1982/Sites/tlaravel4/bootstrap/../app/storage/views/178250f445fac7ac6adce8b5af153a21', array('__env' => object(Environment), 'app' => object(Application), 'errors' => object(MessageBag), 'title' => 'Title Example', 'users' => object(Collection))) in /Users/sangar1982/Sites/tlaravel4/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php line 45
at CompilerEngine->get('/Users/sangar1982/Sites/tlaravel4/app/config/../views/users/index.blade.php', array('__env' => object(Environment), 'app' => object(Application), 'errors' => object(MessageBag), 'title' => 'Title Example', 'users' => object(Collection))) in /Users/sangar1982/Sites/tlaravel4/bootstrap/compiled.php line 15692
at View->getContents() in /Users/sangar1982/Sites/tlaravel4/bootstrap/compiled.php line 15675
at View->render() in /Users/sangar1982/Sites/tlaravel4/bootstrap/compiled.php line 16983
at Response->setContent(object(View)) in /Users/sangar1982/Sites/tlaravel4/bootstrap/compiled.php line 16015
at Response->__construct(object(View)) in /Users/sangar1982/Sites/tlaravel4/bootstrap/compiled.php line 7407
at Router->prepare(object(View), object(Request)) in /Users/sangar1982/Sites/tlaravel4/vendor/laravel/framework/src/Illuminate/Routing/Controllers/Controller.php line 156
at Controller->processResponse(object(Router), 'index', object(View)) in /Users/sangar1982/Sites/tlaravel4/vendor/laravel/framework/src/Illuminate/Routing/Controllers/Controller.php line 126
at Controller->callAction(object(Application), object(Router), 'index', array()) in /Users/sangar1982/Sites/tlaravel4/bootstrap/compiled.php line 7094
at Router->Illuminate\Routing\{closure}()
at call_user_func_array(object(Closure), array()) in /Users/sangar1982/Sites/tlaravel4/bootstrap/compiled.php line 13427
at Route->callCallable() in /Users/sangar1982/Sites/tlaravel4/bootstrap/compiled.php line 13406
at Route->run(object(Request)) in /Users/sangar1982/Sites/tlaravel4/bootstrap/compiled.php line 7114
at Router->dispatch(object(Request)) in /Users/sangar1982/Sites/tlaravel4/bootstrap/compiled.php line 958
at Application->dispatch(object(Request)) in /Users/sangar1982/Sites/tlaravel4/bootstrap/compiled.php line 946
at Application->run() in /Users/sangar1982/Sites/tlaravel4/public/index.php line 49
at require_once('/Users/sangar1982/Sites/tlaravel4/public/index.php') in /Users/sangar1982/Sites/tlaravel4/server.php line 19

我无法找到错误。看来一切都好。

有人可以帮帮我吗?谢谢!

更新了异常日志

1 个答案:

答案 0 :(得分:2)

查看异常时,好像您的某个视图正在调用URL::route('user')。仔细检查您的所有视图,以确保您正在呼叫正确的路线。