I'm using the Laravel PHP framework and am wondering about a few things. The default application/routes.php
file contains this:
Route::get('/', function()
{
return View::make('home.index');
});
This just outputs the view, but how do I call a controller from there?
I can delete the entire route above and replace it with Route::controller('home')
which seems to use the home controller on the default URL (ie example.com/
). But any other controller like Route::controller('article')
doesn't work, only on example.com/article
. How would I set the article controller as the default?
Just pass the controller as a string, with @
between the class name and the method name:
Route::get('/', 'article@index');
Read the docs (scroll to the example by the title Registering a route that points to a controller action ).
The " /
" is special location and you can set it via Route::get('/','home@index')
.
For all other actions on home controller you will have urls such has " /home/action1
" or " /home/action2
".
I am just trying to make you understand that there is no benefit and need of making any controller assign to " /
".
I hope I am clear with my reply. Again this is not an attempted answer to your question but a suggestion for you if you are stuck with route handling. I was at the same stage where you are few days back :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.