Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
URL Route with language
  • Hi,

    I am planning to create a multilanguage website-base, which could be used as a base for any websites. The URL would contain a segment at the beginning of segments like this:
    http://example.com/en/about

    I created an inline route for this:


    	'([a-z]{2})/:any' => function($request) {
    $segments = $request->uri->segments();
    $lang = array_shift($segments);
    $segments = implode('/', $segments);

    return \Request::forge($segments)->execute();
    },



    This removes the first segment, processes it as the language code, the creates a new request for the rest of the route.

    Do you have any better practice? This will be used as a base for various applications (webshop, etc) and it will be published to everyone, so it should not be in a base controller, as it would be a must to extend a base controller.
  • Very clean solution.

    Downside is that it will have some overhead due to the second request.

    I would remove check and remove the first segment in the index.php from $_SERVER['REQUEST_URI'], after calling the app bootstrap, but before firing the request.

    You can store the retrieved language in the Config, or in constant, so it can be accessed by code later.

    Not as clean, but faster.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion