Reputation: 3
I am using CodeIgniter 2.1.1 and building a website using two environments- Production and Testing. Essentially, in the beginning, both the environments have the same program logic. But now there are several modifications to be made.
The idea is to share the controllers and models of production environment and test environment but have different views for both environment.
I have set up WAMP and in the WWW directory there are two separate folders: one for testing, another one for production. There are controllers , models ,views etc under each folder. CI is pointed appropriately and the base URLs are set.
My question is even, when I type the URL in the web browser to invoke controller of test environment, it should redirect and invoke the controller of production environment. Is that possible ?
Upvotes: 0
Views: 279
Reputation: 724
Don't have it redirect. Have it include the file instead.
Assuming you have this file structure:
www-root
|-production
| |-application
| | |-controllers
| | |-etc.
| |-etc.
|
|-test
| |-application
| | |-controllers
| | |-etc.
| |-etc.
|
Create files with exactly the same name in both environments. We'll say controller.php
for our example. In the production environment, do your coding. In your test environment, include this line and only this line:
<?php include '../../../production/application/controllers/controller.php';
This should pull the file from your production environment into your test environment. Just ensure if your hard-coding any links to make them relative as opposed to absolute. This way when it gets pulled into you test environment, it'll make reference to your testing assets and not your production ones.
This is untested as I don't have access to my CI installation right now. Let me know how it turns out.
Upvotes: 1
Reputation: 3867
I would suggest that you ultimately setup some type of version control, such as Git. You can edit the environment on test and push out the changes to production.
To answer your question, you can share the models and controllers between two different apps by setting up a symlink. I've done it in linux, but it should be the same in Windows. So, say you want the actual files to be in the test app. Put all the php files in the controller and model directory of the test app. Instead of creating the controllers and models directories in the production app, just create symlinks to the test app's respective directories.
Upvotes: 0