Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Special route config question, by newbe
  • Hi all, I scratch my head for a couple of days now with that problem. I have a special case for URL routing. Here's the case: we'll have a game, sort of, on which several organisations will have there own branding. The problem is that the URL scheme demanded by my client goes like this: "http://example.com/brandname/home/index"; in english,
    "http://example.com/brandname/accueil/index"; in french. And this should call the same controller/action. Also, the /brandname/ segment in the URL is optional.
    Here's some more examples with there corresponding controllers/actions, if that can help clarify my problem: http://example.com/home/about (controller: home; action: about)
    http://example.com/abrand/home/about (controller: home; action: about; param: brand)
    http://example.com/anotherbrand/home/about (controller: home; action: about; param: brand)
    http://example.com/accueil/apropos (controller: home; action: about)
    http://example.com/abrand/accueil/apropos (controller: home; action: about; param: brand)
    etc. How can I possibly do this? Thanks a lot!
  • You can try to use a regex to deal with this:
    '(.*?/)?home/about' => 'home/about/$1',
    '(.*?/)?accueil/apropos' => 'home/about/$1',
    
    You can then define your method as
    public function action_about($brand = null)
    {
    }
    
    and $brand will contain the brand name is one was included in the URL.
  • ok, thanks, it's working! So using this method means that I have to declare all possible URI request in the route... Well.... If found another way of doing this but it required me to override a couple of the core classes. So that way I only need to fill the route config with french translations. Thanks, we'll decide which way is best for us!
  • Nothing to do about it, there is no way to know to what you want to route /this/that/other. Is 'this' a brand name'? In what language is 'that/other'? Where should it map to?

Howdy, Stranger!

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

In this Discussion