1

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!

3
  • 1
    Will you dynamically generate and write .ctp files for every new user or could it be purely database+template based? Commented Nov 25, 2009 at 8:22
  • 1
    Then I'm not quite sure where the problem is. :-) As far as I understand it's all within the same application then, isn't it? The only problem would be how to pipe requests for company.example.com through your Cake app at example.com, which should be accomplishable with a properly configured server and maybe some .htaccess magic. Or am I missing something in your question? Commented Nov 25, 2009 at 9:29
  • I found the solution (below). I'll accept after a few days if no better answers come in, but I'm assuming this is the best way. Commented Nov 25, 2009 at 9:52

3 Answers 3

1

Solved using this tutorial

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.