Support the ongoing development of Laravel.io →
Configuration
Last updated 2 years ago.
0
Solution

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.

  1. This is just a brief usage, not too practical. :D
// 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()
     {  
     }
}

  1. Not sure if this is the best practice, but you could something like this,
Route::get('foo/{arguments?}', function() {
    $segments = Request::segments();
    // Do whatever you want in $segments array

})->where('arguments', '(.*));
  1. I would suggest using a main layout and load sub-view using Blade. http://laravel.com/docs/templates
Last updated 2 years ago.
0
  1. I decide to use your suggested approach.

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.