Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How can I switch theme depending subdomains ?
  • Hi FUELers ! I need your help.
    Before beginning, sorry for my english, I'm a fuel french developer ;)

    I've built a tree structure page with the nestedset Model.

    Example :
    • Fruits
      • Orange
      • Cherry
      • etc....
    • Vegetables
    • Fish
    I have :
    - A Main Domain : food.com with a main menu : Fruits | Vegetables | Fish

    I want
    - A Subdomain : fruits.food.com with a main menu : Orange | Cherry | etc...


    How can I make this :
    food.com/fruits/orange -> fruits.food.com (a child website with the same structure but with a different Tree Root Node)

    Where must i check the subdomain to switch theme and change my tree node route?

    - In my Public_Controller with a router method
    - Extend the Core Request Class?

  • HarroHarro
    Accepted Answer
    Pas de problème, Brice. ;-)

    If it is only a switch of active theme, you can do that in the theme.php config file. After all, it's just a php file like any other.

    It could be something simple like:

    switch (\Input::server('host'))
    {
        case "food.com":
            $theme = 'main';
            break;
        case "fruits.food.com":
            $theme = 'fruits';
            break;
        default:
            $theme = 'default';
    }

    return array(
        'active' => $theme,
    );

    Or if you want it more clean, create a static helper class for it, and do:

    return array(
        'active' => \Themehelper::detect(),
    );

    and abstract the detection code away from the config file.

Howdy, Stranger!

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

In this Discussion