views:

211

answers:

3

Hi guys,

Our website is going to work as follows:

  • There's a central site www.example.org where everybody can register, change information, manage their 'business card'.
  • Also, everybody will have companyname.example.org. Here users can publish a simple site based on information they change in the main site.

This site is being built on CakePHP. I'm wondering what a good setup for this is. After doing some googling it appears to be common to create a separate directory for controllers and models for reusing, but in this case I want to really share all the code, except routes and views.

Is it possible to change routes based on a domainname. Would this be considered 'appropriate' for CakePHP at all. Rather than a solution that 'does' the job, I would prefer to find the best practice.

Thanks!

+1  A: 

Solved using this tutorial

Evert
+1  A: 

Off the top of my head, the routing engine in CakePHP has no concept of domains so what you could theoretically do is map a route eg /company1/post/1 to company1.example.com/post/1 using Apache rewrite

Prefixing in routes is possible as I've used it before to produce a multilingual site eg /en/blog, /es/blog etc so it would be just a case of prefixing the company name in the route.

Mathew Attlee
+1  A: 

What you are looking for are themes.

CakePHP 1.3 has a neat implementation of that, but 1.2 works almost as good.

In your AppController, you will want to add something along those lines to load a different theme based on the host:

$mapThemes = array('company.example.com' => 'theme-1', 'store.example.com' => 'theme-shopping');
$this->theme = $mapThemes[env('SERVER_NAME')];

Of course, possibilities are endless. You can load $mapThemes from the database by letting every user define multiple themes, etc. But that's the general idea and what I believe is the Cake way of doing things.

JadB