Domanda

I'm a Laravel 3.x beginner with a CI background.

I'm very acquainted to use controllers rather than routes and I'm having issues trying to use controllers in Laravel.

For example: let's say I have the home_controller and the "about" action. My problem is that I'm only able to access the "about" action by setting a route that points to it - something I think is undesirable.

Is there a way to get the "about" action to work without setting a route?

È stato utile?

Soluzione

In laravel, everything can be accomplished using either Routes and/or controllers.

However, using both routes AND controllers is suggested for great flexibility. See this article for more informations and some examples of how to combine routes with controllers.

Anyway, if you want to use controllers (which is perfectly acceptable), you need to register them in your routes.php with Route::controller('yourcontroller') before you can use them.

Altri suggerimenti

Everything has to be routed in Laravel. But, you don't have to manually route each method. You could do something along the lines of Route::controller('admin').

See here: http://laravel.com/docs/routing#controller-routing

I like Mike Anthony solution. When you're using only controllers this detect method is everything you have to do - this will register automatically all of your controllers. Best hand free solution so far. The usual controller registration is, as the guys already mentioned, this:

Route::controller('controllername');   

You have to register all controllers like in the example above. It is one line of code per a controller, and it is the rule. But if you have a static page or a login action (page), a good practice is to create a Route controller (anonymus function), not a classic controller (in controllers folder).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top