路由整个控制器

I'm trying to route an entire controller with laravel 4 using this:

Route::controller('mycontroller', 'MyController');

When user comes to this url:

http://my.app/mycontroller/anyMethod

then anyMethod method in MyController should work.

It should work for all methods defined in that class.

Currently when i go to: my.app/mycontroller, it throws NotFoundHttpException

when i go to: my.app/mycontroller/aDefinedMethod, it throws NotFoundHttpException and says: Controller method not found.

What is wrong?

UPDATE: As i understand, Route::controller() is now restful in Laravel 4. Ok then, i don't want a restful controller and i don't want to rename my methods. So how should i setup a route to achieve this?

You're defining it as a RESTful controller. my.app/mycontroller/index will correspond to a method called getIndex().

Without seeing your controller - the issue is probably you a not defining a 'restful' controller functions. Route::controller() is now restful in Laravel 4 - See here for more info.

So therefore when you go to url

http://my.app/mycontroller/anyMethod

then it should be

getAnyMethod() in your MyController

You have a few issues here. One is you need to prepend the action you are looking for to the method name. So for example, your method name should read getAnyMethod() and it would respond to mycontroller/any-method.

If you do not want a RESTful controller, you should register all your controller's functions with named routes like shown below, so that Laravel 4 can properly reflect to a particular method of a particular controller and execute it, when you enter the url in your browser.

Route::get('yourcontrollerslug', array('as' => 'your.route.name', 'uses' => 'YourController@someFunctionOne'));
Route::post('yourcontrollerotherslug', array('as' => 'your.route.othername', 'uses' => 'YourController@someFunctionTwo'));

In the L4 documentation it is reffered to mapping route names (and in result the particular routes) to controller actions.

// You may also specify route names for controller actions:

Route::get('user/profile', array('as' => 'profile', 'uses' => 'UserController@showProfile'));

Maybe there actually are other ways to achieve what you want in a more convenient manner - but I am not aware of such :)

Hope this helps you out anyway.