2 Websites, 2 Domains, Same codebase |
[eluser]JanDoToDo[/eluser]
Hey guys, I want to have two websites with different domains but with the same codebase but different views. It would be similar to a "white label" situation. Could someone point me to some resource about how I would do this? They would share some of the information in the database, but other information would be site specific. i.e. I want www.site1.com and www.site2.com. Each site would have its own "application" folder but the only difference between them would be the views as they represent different clients. There could be 10 or 20 different companies and hence would need the equivalent number of application folders. What would be the best way to achieve this? They would also be on the same server so the different domains would just be setup in the dns records to point to the different application folders, or should I approach it a different way?
[eluser]JanDoToDo[/eluser]
Thanks for your reply! The problem with that one is that some of the data is global and so would need to connect to two databases! How would I accomplish this?
[eluser]pickupman[/eluser]
[quote author="JanDoToDo" date="1274009391"]Thanks for your reply! The problem with that one is that some of the data is global and so would need to connect to two databases! How would I accomplish this?[/quote] User guide wins again. You could then use a conditional php tag to set the DB variable like: Code: $DB = ($_SERVER['HTTP_HOST'] =='www.site1.com') ? 'group_1' : 'group_2';
[eluser]JanDoToDo[/eluser]
Ok.. thanks for that. Another point - If I have different users for different domains then (based on the users have an auto incremented id) the user ids would overlap as the user ids would conflict between the two databases. Also, if I was selecting a user based on their use id, I would not know from which database to get it from. Alternatively, I could just one one database with a column for which domain the user is from but that doesnt seem as good as having separate db/tables? how would you go about this?
[eluser]pickupman[/eluser]
[quote author="JanDoToDo" date="1274106140"]Ok.. thanks for that. Another point - If I have different users for different domains then (based on the users have an auto incremented id) the user ids would overlap as the user ids would conflict between the two databases. Also, if I was selecting a user based on their use id, I would not know from which database to get it from. Alternatively, I could just one one database with a column for which domain the user is from but that doesnt seem as good as having separate db/tables? how would you go about this?[/quote] I guess I am confused, because you mentioned you would be using separate databases, but sharing views. If you are looking to use the same user table, but have different data tables, how about a table prefix. (site1_pages, site2_pages). Use one database, can call your table names dynamically. Code: class Pages_model extends Model{ You would probably want to extract part of the domain name using explode() or something rather than the whole domain name for a table prefix.
[eluser]icomefromthenet[/eluser]
I would stick with a single application folder and just segment the view files into new directories. so have something like below. --------------- system application --views --site 1 --site 2 --site 3 ---------------- Document Root ---------------- assets --site 1 --site 2 --site 3 site 1 --index.php set app folder to (../../application) site 2 --index.php set app folder to (../../application) site 3 --index.php set app folder to (../../application) --------------- With the database I would create a user database to store, each user inside you can set which site /sites they belong too In your user model just use codeigniters second db connection inside each method just open new second db connection. $DB1 = $this->load->database('group_one', TRUE); $DB1->get();
[eluser]JanDoToDo[/eluser]
ok thats cool cheers! By the way you're saying it though every site would have the same application folder, so i wouldnt need to set the path in index.php? Also, if I wanted each of the other sites to look like a subdomain of my own, how would you go about that? so like site1.mainsite.com, site2.mainsite.com etc
[eluser]icomefromthenet[/eluser]
I'm in the same boat now, the two easiest ways I found to configure apache for multiple named virtual hosts, (hard to maintain) with a wild card in the ServerAlias, like '*.localhost.com'or use ModAlias to map subdomain to directories. If you need alot of flexibiliy try mod-rewrite. About the paths, you would need to set both the system and application paths in all index.php in the setup above should be set to (../../application),(../../system) |
Welcome Guest, Not a member yet? Register Sign In |