Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
one routing used to multiple module
  • Hi, I have a Problem when I want to create routing for my application I have 2 flow in my application

    first, multiple languages routing
    second, singgle language routing

    here my routing configuration for frontend

    ':lang_code'/(:any) => 'pages/frontend/pages/details/$1', // this routing refer to module page with controller  pages under folder frontend and method details with params 

    //this is for singgle language 
    ':any' => 'pages/frontend/pages/details/$1', 

    the problem is how to refer that routing into multiple module, I have another module example 'news' , how to point this ':lang_code'/(:any) into module pages and news ?

  • You can't.

    Currently, module routes are only loaded when the module is loaded, which is not going to happen if the URI doesn't start with '/news/'...

    Most multi-laguage solutions strip the language code from the URI before it is processed by Fuel.

    The quickest way is to overload Input::uri(), something like this:

         * Detects and returns the current URI based on a number of different server
         * variables.
         * @return  string
        public static function uri()
            if (static::$detected_uri !== null)
                return static::$detected_uri;


            $segments = explode('/', static::$detected_uri, 2);

            if (isset($segments[1]) and in_array($segments[0], array('en', 'fr', 'de')))
                // langauge is in $segments[0], store it somewhere (config, new input method, etc)

                // remove the language from the uri
                static::$detected_uri = $segments[1];

            return static::$detected_uri;

  • Hi actually I have place my route inside config.php global not in module config.
    maybe I have been imagined your code and i think that is not problem if using another way like that.
    so this point is I cannot route one url into multiple module ? if I want to route like that just giving path name of module ? : 

    ':lang_code/pages/(:any)'    => 'pages/frontend/pages/details/$1',
    ':lang_code/news/(:any)'    => 'news/frontend/news/details/$1',
    ':lang_code/testimonial/(:any)'    => 'testimonial/frontend/testimonial/details/$1',

    'pages/(:any)'    => 'pages/frontend/pages/details/$1',
    'news/(:any)'    => 'news/frontend/news/details/$1',
    'testimonial/(:any)'    => 'testimonial/frontend/testimonial/details/$1',

    and in my controller just detected configuration site using multiple language or not if use that I should detection path of route :lang_code by using $this->param('lang_code'); and then process another code.

    //under page controller and another module (news,testimonial,ect)  possible same
    public static function action_details($name) 
    $page = array();
    if (\Common::multiple_languages() === 'yes')  {
    $lang_code = $this->param('lang_code');
    $page = //----- doing code for get page by filtering language---//
    //return page response;

    // for singgle language 
    $page = //----- doing code for get page by filtering language---//
    //return page response singgle language

    from that code and routing it's possible one url with same content and that is will be problem in SEO, example if I am using multiple_language  = yes, so the url for http//:example.domain/en/news/hot-news show content by english language.

    and then I can also access  single language url http//:example.domain/news/hot-news then show content same with english language.

    it's possible to active or inactive routing with statement from controller, example I am inactive route for singgle language when system detection multiple_language = yes ? sorry for my bad english

    any suggestion ?
  • As long as you define your routes globally, it's not a problem.

    From an SEO point of view, my suggestion will not have any impact. I've just pulled the language detection bit out of all your controllers, and centralized it.

    if in the Input extension you store the detected language in a static property, and add a new method for retrieving it, you can replace your $this->param() call with \Input::uri_language() or something, and the rest remains the same.


Howdy, Stranger!

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

In this Discussion