multiple applications with codeigniter from same framework directory? - codeigniter

could i use one codeigniter framework directory to create multiple applications?
cause it seems that i have to have separate codeigniter folder instances for different applications. i want to be able to adjust some code in one place (classes that are universal) and every application i created with codeigniter will be affected.
with yii you could do this.

you can do this folder structure:
system
website-1 (your application)
----application
----index.php
website-2 (your application)
----application
----index.php
website-3 (your application)
----application
----index.php
move the 'codeigniter application folder' from the system and put it in one of you application folders.
copy the index.php file and paste inside your application folder.
In the index.php file:
YOu should have the following:
$system_folder = "../system";
$application_folder = "application";

Both Colin and Thorpe are correct.
Out of the box, sharing is not perfect. If you want to share libraries you have to put them in the system/libraries folder which makes upgrading that little bit more difficult and models cannot be shared at all.
To created a "shared" directory for libraries and models then you can use this MY_Loader.

could i use one codeigniter framework
directory to create multiple
applications?
Yes, you can create multiple applications with one CodeIgniter instance

Related

is it important to use the same directories for views and models

is it important to use the same directories for views controllers and models or you can be free to create files inside created folders and refer to them when needed
in Laravel MVC
Check docs Directory Structure
The default Laravel application structure is intended to provide a great starting point for both large and small applications. But you are free to organize your application however you like. Laravel imposes almost no restrictions on where any given class is located - as long as Composer can autoload the class.
I myself haven't tried doing my own folder structure. I would personally stick with the standard created by Laravel and follow that.

codeigniter multi apps using 1 system, 1 database

i would like to achieve the following file structure with codeigniter:
these folders above www
ci/system/...
ci/application/site_1/config/config.php
ci/application/site_2/config/config.php
these folders under www
www/site_1/index.php
www/site_2/index.php
Both sites are using the same codeigniter system file.
Both sites are having the same php code.
Bot sites are using different set of mysql tables as I have only 1 mysql database and i intend to use table prefix to differentiate them. eg.
site1_login
site1_register
site2_login
site2_register
Any advise on how to configure the index.php file and config.php file, thanks.
Idea of application folder being separate to system folder in CodeIgniter is that you can have different applications with same system folder. I would be structuring it as follows:
/base/system
/base/application_1
/base/application_2
/base/webroot/site_1/index.php
/base/webroot/site_2/index.php
Then change to 2 index.php files to point to the relevant system and application folders. In both application folders, I would be pointing to the same DB details as well.

How to add custom code to the 'system' folder of CodeIgniter?

I am looking into building my own CMS / extended framework on top of CodeIgniter, and I was wondering how to structure it to keep code out of the application folder. I noticed that in a typical CI set up, the file structure looks like this:
application/ //code for your application
system/ //CodeIgniter core
index.php
However, in PyroCMS, They have used the following structure:
application/ //code for your application
system/
--cms/ //PyroCMS core
--codeigniter/ //CodeIgniter core.
How do I accomplish a similar result?
To emulate that structure just edit the index.php constants:
APPPATH
BASEPATH
#WebweaverD has provide you a good solution to improve your application usgin HMVC. I will give you another.
How about something like this:
-system/ //CI core
-index.php //manage the front_end requests
-acp.php //manage the back_end requests
-apps/ //applications dir
--back_end/ //only "admin" controllers, libraries, config. No views here
--frond_end/ //only "user" controllers, libraries, config. No views here
--acp/ //views for back_end
--themes/ //views for front_end
All above can be implemented as you want only extending the necessary core files.
The short answer is that everything starts from index.php, this is where core/CodeIgniter.php is included and it is also where application and system paths are set (retrieving values from config).
I think that pyro cms actually sets /system/cms as the application folder, presumably they have written code which looks at the presented application folder for content and processes it.
Another approach is to use wiredesigns modular HMVC:
https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc
This will allow you to separate your code out into modules. Just have a folder called cms containing all your cms modules and another folder to build your custom content on top.
You set the path to your modules folder in the config so if you wanted your cms code in the system folder you could set the path to your modules folder there and build on top using codeigniter in the standard way, perhaps adding a hook before or after your controller is loaded to call the cms core.
Mine is just a suggestion but you can easy fork pyrocms and build your own cms on it.
PyroCMS will deprecate codeigniter in the next version so you can keep their code and fix it where you need and modify it as you want

Creating an admin section controllers and views in Code Igniter 2.0

I have created my site with controllers such as about, products etc... which gives me example.com/about/ etc..
How would I create a admin section with the same controller name, like example.com/admin/about or example.com/admin/products ?
How do I organize my controllers?
2 more options to compliment WebweaverD answer.
Use Modular Separation
Create a second application folder and index file, that will be responsible for admin, connect them to the same system folder.
The second option is really easy to manage once you have set it up. There are variations but I find the structure below to be the most convenient.
mykewlwebsite.com
apps/
frontend/
app/ frontend codeigniter application folder
public/
index.php
assets/ frontend js, css, images
backend
app/ backend codeigniter application folder
public/
index.php
assets/ backend js, css, images
config/
database.php
constants.php
system/ codeigniter system folder
The database.php file contains the code from CodeIgniter's config/database.php and is shared for all applications of your project - simply remove all code and add require_once('../../../../config/database.php'); to the config/database.php
index.php files inside public folders have two important variables $system_path and $application_folder, change them to
$system_path = '../../../system/codeigniter';
$application_folder = '../app';
constants.php file can have some constants like the ENVIRONMENT constant from the index.php files and some other. Just require_once() it from the index.php files.
Though there are pros and cons.
PROS
For those of you, who are developing on localhost and deploying to servers via FTP or other systems can simply upload one folder - apps and overwrite the target folder without fear of overwriting database.php settings (I'm sure most of you have them different from the local ones).
Adding one more application is easy - just duplicate one of existing. You can add as many applications as you want - api, ajax, user cabinet, etc.
CONS
This structure is meant to be used if you have a domain as mykewlwebsite.com and have the ability to add sub-domains to it, so you just configure the home folders for each of them:
mykewlwebsite.com: path/to/mykewlwebsite.com/apps/frontend/public/
admin.mykewlwebsite.com: path/to/mykewlwebsite.com/apps/backend/public/
api.mykewlwebsite.com: path/to/mykewlwebsite.com/apps/api/public/
You have a few options here:
1) CREATE A SUBFOLDER - Put them in a folder called admin within the controllers directory (in application/contollers/admin/products.php)
A word of warning here is that you can only go one folder deep or codeigniter gets upset. Also, it will use first level controller/methods first so be careful of naming conflicts - e.g if you have an admin controller with a products method in it, that will get called before it looks in the admin directory for a products controller. (when going to example.com/admin/products)
2) USE THE ROUTES FILE - If it is just the urls you are worried about you could just call the controllers whatever you want and use the application/config/routes to redirect those paths to the controllers you want like this:
controller name: admin_products.php
routes file:
$route['admin/products'] = "admin_products";
3) USE A MASTER CONTROLLER FOR ALL - Final option would be to have a single admin controller and use named methods inside it, so for example you have admin.php controller with a products method within it this would then be called by admin/products uri (this will probably get messy though in a big application/site - not recommended)
Hope I have explained this OK for you, if you need any clarification please ask and I will try to elaborate.

CodeIgniter How to create Multiple Site with One CMS

I want to create a blog site with only one CMS. This CMS will be in different domain.
For example: mycms.com
Then my blog sites are also in different domains.
For example: website1.com, website2.com, website3.com
They will all use mycms.com as their admin
*Images will be uploaded in mycms.com/images/ so all the 3 websites will get the images from this directory
If images are loaded on website1.com from the main database, they should be displayed as if they're from website1.com. So for example website1.com/images/cat.jpg instead of mycms.com/images/cat.jpg
How will I build this using codeigniter?
You can use the same CodeIgniter /System and /Application folders for all the websites if you like; just make sure all the index.php files are setup to use those same folders for $system_path and $application_folder respectively. Note that these sites also need to reside on the same server.
You can serve up different content by checking $_SERVER['HTTP_HOST'] for the domain the request came from.
As for htaccess you should be able to use %{HTTP_HOST}/$1 or %{HTTP_HOST}$1 (depending on server config) to make the rewrite rule dynamic.
I am actually building a similar project right now using CodeIgniter but there are also several other projects available like halogy, codefight, pyro (with an extension), and many others.
CodeIgniter has a System and an Application folder. You could have one global system folder and then one application folder for each of your subdomains, or you could have one application folder and just make your subdomian folders parallel with your www folder.

Resources