Controller Route not found in Laravel 4

柔情痞子 提交于 2019-12-13 15:36:01

问题


I am in the process of migrating from L3 to L4. When registering the HomeController controller that came with the default L4 installation, trying to go to the page www.domain.com/home gives me a ResourceNotFound exception. I did a composer dumpautoload but that did not help.

Did I miss out an additional step?

routes.php

Route::controller('home', 'HomeController');

controllers/HomeController.php

<?php

class HomeController extends BaseController {

    public function showWelcome()
    {
        return View::make('hello');
    }

}

Error Stacktrace

NotFoundHttpException:
in /var/www/l4/vendor/laravel/framework/src/Illuminate/Routing/Router.php line 1338
at Router->handleRoutingException(object(ResourceNotFoundException)) in /var/www/l4/vendor/laravel/framework/src/Illuminate/Routing/Router.php line 992
at Router->findRoute(object(Request)) in /var/www/l4/vendor/laravel/framework/src/Illuminate/Routing/Router.php line 956
at Router->dispatch(object(Request)) in /var/www/l4/vendor/laravel/framework/src/Illuminate/Foundation/Application.php line 463
at Application->dispatch(object(Request)) in /var/www/l4/vendor/laravel/framework/src/Illuminate/Foundation/Application.php line 448
at Application->run() in /var/www/l4/public/index.php line 51

回答1:


As per the documentation:

Next, just add methods to your controller, prefixed with the HTTP verb they respond to

So:

class UserController extends BaseController {

    public function getIndex() 
    {
        // Would response to /user and /user/index
    }
}

So, in your case simply renaming showWelcome() to getWelcome() should suffice.




回答2:


Try changing your route to this:

Route::resource('home', 'HomeController');

UPDATE: My bad, I thought you wanted a resourceful controller, as described here: http://four.laravel.com/docs/controllers#resource-controllers

For "normal" RESTful controllers juco's answer seems right.

If you want basic controllers, you can use this to correspond to your controller method:

Route::get('home', 'HomeController@showWelcome');


来源:https://stackoverflow.com/questions/15588409/controller-route-not-found-in-laravel-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!