Just my 2 cents. :D
I came from a CI background and had the same feeling as you when I first started to use Laravel. The question: Where did the dynamic routing go? After reading this from the guy who actually participate in developing CI, I started to re-think about auto-routing. http://philsturgeon.co.uk/blog/2013/07/beware-the-route-to-evil
Whether we should use auto-routing is still remained an open question. ( It is indeed some sugar in the beginning of the development ) The bottom line is that, automatic routing sometimes might lead to unexpected result when someone hits a route that isn't expected to be exposed.
Laravel routing starts to make sense to me because I have complete control on how the route should look.
Back to the question you have asked.
// Static pages, NO controllers involved.
Route::get('{page}.html', function($page) {
// views/static/*.blade.php
$dir = 'static.';
if(View::exists($viewPath = $dir.$page)) {
return View::make($viewPath);
}
else {
// views/errors/not_found.blade.php
return View::make('errors.not_found');
}
});
// I personally DO NOT recommend this usage.
// As this approach is considerably dangerous and tedious to "simulate" the same action like CI
// For controller-like usage, briefly. NOT practical and Validation required.
Rout::get('{controller}/{action}', function($controller, $action) {
$controller = ucwords($controller).'Controller';
App::make($controller)->{$action}();
});
A better approach could be
// In this case, Route order matters, if you have the above static pages route setup.
Route::controller('user', 'UserController');
UserController.php
class UserController extends BaseController {
public function getIndex()
{
}
public function postIndex()
{
}
}
Route::get('foo/{arguments?}', function() {
$segments = Request::segments();
// Do whatever you want in $segments array
})->where('arguments', '(.*));
2 and 3) Yeah I reading more documentation on Laravel website and looks like I need to migrate my coding style. Goodbye CI, then. LOL.
Thanks.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community