Search code examples
phpcakephp

Different data sets per subdomain in Cakephp?


I am writing a personal bookmarks application and am looking for a way to have totally different content between subdomains.

I have written the application and it works fine, but have yet to implement multiple collections. I have the following models:

  • Tag (unused so far)
  • Bookmark
  • Subject

Bookmarks are categorized in subjects and I'm planning to allow tagging in the future and see if that helps me manage my bookmarks more easily.

The current problem I have is that I'd like to separate bookmarks as a whole. I want to use subdomains like webdevelopment.bookmarks.local, languages.bookmarks.local, linux.bookmarks.local that work with an entire own set of domains and bookmarks.

I am considering adding a new model called Set (short for "bookmark sets") and defining sets based on the subdomain.

According to that plan I'd have to rewrite all $this->...->find-queries in the entire App to contain the condition "set_id" = $SubdomainBasedSetid".

While it wouldn't be that much work, I was wondering if it could be done smarter, maybe that Cake would only see the relevant bookmark set per subdomain.


Solution

  • well, your solution is right. But instead of using subdomains, you can use prefix, so you don't have check and set yourself. Since you use subdomains, I assume that these sets are fixed or rarely change. So you don't really need a sets table, just use the set name directly in your bookmark record, so you don't have to convert between name and id.