Welcome Guest, Not a member yet? Register   Sign In
Multiple sites, same codebase?
#1

[eluser]jbawarren[/eluser]
What would be the easiest way to set up multiple sites that share a common codebase? For instance, if I wanted to create multiple restaurant websites from a single domain (i.e. restaurants.com/joescrabs, restaurants.com/samsfish, restaurants.com/megsbagles, etc.)

How would this work without a lot of duplication?
#2

[eluser]Adam Griffiths[/eluser]
You could set folders in your controllers to be controllers/joescrabs, controllers/samsfish and controllers/megsbagles - then when accessing the site restaurants.com/joescrab you are "taken" to the joescrab folder, which would make use of the same models and possibly even the same views.

I know you said you didn't want too much duplication, but you could just put the differences in the controllers for each site into their own folder, and then use universal controllers in the controlers/ folder.

Just an idea.
#3

[eluser]SneakyDave[/eluser]
the following method might be overkill if all of your restaurants are going to have the same function and use the same views, controllers, and databas, but its a pretty common setup.

What I've done in the past, is put the CI system folder outside of the root, such as if the restaurant.com's web root was:

/var/www/html/

I'd put the CI system folder in /var/www/

Then in /var/www/html/ you can have your "application" directories in there, named after the restauruant names

/var/www/html/joescrabs
/var/www/html/samsfish/

each of your restauruant folders is an "application" directory to CI, with its own configs, views, etc.

You will have to make adjustments in your application/config/config.php file to tell your app where CI is, and where your "application" folder is.
#4

[eluser]jbawarren[/eluser]
Thanks for your replies. Adam, how do you suggest I abstract the differences from the common Controller functions? Would it be a sub-controller? So, if restaurant extends Controller, then would differences extend restaurant? I'm just trying to get an idea of a best practice for this type of thing.
#5

[eluser]m4rw3r[/eluser]
You can add a few base controller classes in the libraries/MY_Controller.php, then they gets autoloaded automatically for all controllers (but not instantiated).
#6

[eluser]metaltapimenye[/eluser]
this kind of stuff i work out with my last apps.
(read URI Class; Model)
url:http://www.mylandingsite.com/index.php/primary_class/restaurants/&lt;?php $this->uri->rsegment(2);?&gt; <--- this $this->uri->rsegment(n) stuff could be a variable to directing the methods behind.

in controller:

Code:
class primary_class extends Controller{
  function Gift(){
    parent :: controller();
  }
  function restaurants(){
    $page=$this->uri->rsegment(2);
    
    $this->load->view($page)
  }
}
#7

[eluser]Adam Griffiths[/eluser]
[quote author="jbawarren" date="1218528614"]Thanks for your replies. Adam, how do you suggest I abstract the differences from the common Controller functions? Would it be a sub-controller? So, if restaurant extends Controller, then would differences extend restaurant? I'm just trying to get an idea of a best practice for this type of thing.[/quote]

That's how I would do it. Just extend the restaurant controller for each site.
#8

[eluser]jbawarren[/eluser]
Thanks guys. This certainly gives me a few ways to approach the issue.




Theme © iAndrew 2016 - Forum software by © MyBB