问题
I am a new addition to the world of CakePHP, and have only created / followed the blog tutorial, and extended it with users. I have been reading the 2.0 book to become more familiar with the framework.
Before I commit to moving to CakePHP, I have a couple of questions.
Currently, I develop a multi domain / multi theme CMS system which is procedural PHP. By doing this I have been able to create a single system on a single database with multiple domains and themes.
I take the $_SERVER['SERVER_NAME']
and look it up in a table of "brands" and then return a brand_id and theme directory. I then suffix all my SQL queries with "and brand_id = X".
I am looking to move over to Cake as the current platform has become overwhelming in size and complexity.
So in short...
Can I create an application with One Core, One App, One Database that can serve Multiple Domains and Themes?
Would I use $_SERVER['SERVER_NAME']
to look up the domain and return back a brand_id and theme?
I don't really want to have multiple databases, as if we had a large number of customers making changes across all databases could prove time consuming.
I certainly don't want to have multiple controllers and multiple models, but in some cases we would want a bespoke view if a customer had a specific requirement.
Any guidance on a basic configuration to get me started would be great. Would each Model "belong to" a "brand"? How would you "serve" up a brand?
Name: Brand1 Domain: www.brand1.com ThemeDir: Brand1
Name: Brand2 Domain: www.brand2.com ThemeDir: Brand2
回答1:
I have a similar situation in which I am using wildcard subdomains. I accomplished this by doing a combination of things.
In my bootstrap file I am reading in my subdomain and assigning it a value to the cakePHP cache. In my case I am calling:
Configure::write('SubdomainHTTP', $myvalue);
This would be your domain name in your case.
I am loading in my routes.php file a filename called subdomainRoute.php. This file checks to make sure that the route or subdomain in my case exists in the database. It concludes by writing the subdomain name and theme name using Configure::write like step 1.
App::uses('SubdomainRoute', 'Routes');
I glue it all together here, in my AppController.php I read the information I write in step 2. Specifically the theme name and set it using:
$this->theme = $yourtheme;
This should allow you to have different domain name themes. Given you will have to have a database to hold a list of domain names and there theme names.
来源:https://stackoverflow.com/questions/17886916/cakephp-one-core-one-app-one-database-multiple-domains-multiple-themes