mvc components in codeigniter? - model-view-controller

in yii i could have mvc components (acts like an own application). could i have this too in codeigniter?
eg. in SYSTEM/APPLICATION have a folder called COMPONENTS and in there i put stand-alone applications that would be a part of the application. components like ADDRESS BOOK, MAIL, TWITTER and so on. every component folder has folders like: models, views, controllers, config etc.
so a component model extends the application model which in turn extends system's (code igniter) model. the same goes for view and controller.
i've already got a lot of these components which i want to use in codeigniter. is it good idea to place them as i said in SYSTEM/APPLICATION/COMPONENTS or is there best practice for this?

You can do this in CodeIgniter using v1.7.2 or 2.0, but using Packages as Billiam suggested would not work and sadly he is just confusing you.
You are basically looking for a HMVC architecture and this can be provided with a system called Modular Separation.
That works with CodeIgniter 1.7.2 and I have patched it to work with the (still unfinished) CodeIgniter 2.0 branch on the link in the entry.

Not by default in CI 1.7.2, but 'packages' will be available in 2.0.
Added ability to set "Package" paths -
specific paths where the Loader and
Config classes should try to look
first for a requested file. This
allows distribution of
sub-applications with their own
libraries, models, config files, etc.
in a single "package" directory. See
the Loader
class documentation for more
details.
From: http://bitbucket.org/ellislab/codeigniter/src/tip/user_guide/changelog.html
Also, take a look at Modular Extensions - HMVC

Related

easy hack for routing codeigniter to third_party examples files

I have to install 10+ APIs in my third_party folder, each has it´s own examples files for testing oauth validation and other features.
without too many changes, has anyone found an easy way to hack the Codeigniter routing to execute files like
$route['hackToken'] = "/application/third_party/googleads-php-lib-master/examples/AdWords/Auth/GetRefreshToken.php";
Codeigniter expects to find a class derived from Controller at the target of a route. So, you will not be able to do this unless you create a Controller for each example.

use boilerplatejs with codeigniter

What is the best way to use codeIgniter with BoilerplateJS? should I put the codeIgniter folder in a BoilerplateJS folder or the contrary? Or something else? Need to make an authentifcation page in codeigniter and redirect the application in boilerplateJS.
Thanks.
I tried BoilerplateJS with CI in the following way:
Basically this is including BoilerplateJS in CodeIgniter folder.
I included all the BoilerplateJS code except the index file in to a folder named public which is in the root folder of CodeIgniter. The index file is placed in the views folder and will be loaded by a controller. (See the image)
For this to work some file paths had to be tweaked.
File paths in boilerplatejs index file (boilerplate.html in my case) had to be changed as follows:
./libs/jquery/jquery-min.js >>to>> public/libs/jquery/jquery-min.js
./libs/underscore/underscore-1.3.3.js >>to>> public/libs/underscore/underscore-1.3.3.js
and so on.
In main.js requirejs path configurations should be changed to:
require.config({
//Let's define short alias for commonly used AMD libraries and name-spaces.
paths : {
// requirejs plugins in use
text : 'libs/require/text',
i18n : 'libs/require/i18n',
path : 'libs/require/path',
// namespace that aggregate core classes that are in frequent use
Boiler : './app/core/_boiler_'
}
});
And in your controller you can load boilerplatejs by: $this->load->view('boilerplate.html');
I was thinking of integrating BoilerplateJS and CodeIgniter and probably use codeignighter-rest server for some time.
If all goes well I will share the code within the week.
A sample project is available at: https://github.com/slayerjay/codeigniter-boilerplatejs
EDIT Adding my view on CodeIgniter and BoilerplateJS
Firstly I have not (yet) done any major projects with BoilerplateJS and Codeigniter. But I have done projects using CI and the CI REST Server and know BoilerplateJS in and out.
I do not have much experience with other PHP frameworks (I have meddled with cakePHP and some others) but for me CI helps me to organize my code according to MVC pattern in a clean way, and provides excellent helper libraries and documentation.
As the OP rightly said, authentication is handled best outside BoilerplateJS and this can be done nicely with something like ion-auth for CI. After the user is authenticated and the SPA is loaded, the rest of the calls will be handled by the CodeIgniter REST server.
In this case you won’t be using much of the View aspect of your MVC architecture, but CI’s models and helpers would be of great help.
If you just need a simple REST server you can go with some lightweight solution that just provides REST type routing, but in many cases you will need to interact with a database and do some data processing.
So if you have decided to have a PHP backend for your application, Codeigniter with the REST server is a good choice.

injecting web module into ASP.NET MVC3 application

i am developing an ERP Application, and wanted to structure it in such a way that, i can inject some other MVC web modules into its AREA at later time. this is what something like ORCHARD does. i need to know any such solution available?
to further elaborate my question, consider my application Named "MyERP" has two sub modules in its area.
1. HRM.
2. FRM.
and released this application to my client. later after release i decided to include another module for (AMS)Attendance Management System. so i wanted to structure MyERP in such a way, that my client can install this AMS module through MyERP web interface.
You may take a look at the following article which illustrates how a sample plugin system could be implemented. The project uses the custom virtual path provider that was presented in the following article and which allows to embed razor views as resources into separate assemblies.
i found this article helpful for my question.

Why do we put MY_Model in the core folder?

In the video tutorials here I can see that MY_Model.php is placed in the core directory of my CI application just like MY_Controller.php would be.
My issue is that CI does not load models from the core directory. I have stepped through CI and found that CI is only checking the application\models folder for models, not the core folder (found on line 279 of CI 2.1.0 Loader.php file). This makes it so I cannot access MY_Model directly using $this->load->model('MY_Model'), though I can extend it just fine.
This makes me wonder why we are putting MY_Model.php in the core folder. Any model that is in application\models can be extended AND accessed directly, so why not put MY_Model.php there?
The reason for making MY_Model.php is extending Core model. Its not supposed to load using this->load->model('MY_Model'). Its already autoloaded. The aim of MY_model is making common method, properties for all model inside application/models without hacking the Core files. And if you have extended Core Model, you should write your application models with extending MY_Model not the CI_Model.

MVC/Codeigniter file structure

I have been doing a lot of research on MVC and file structure. Mainly I've been looking at how to start a new layout. I have downloaded a few open source applications to take a look at file structure and how files are developed.
In the first application it was set up to use the standard way (at least the way it seems to me) of putting all the controllers, models and views each in their respective folders. This is the way that all the books say to do it.
In the second application, all folders are in a modules_core or modules folder where each controller (at least what I would assume to be controllers) are in a folder in there that contain three folders: controller, model, view.
Which of the two versions is accepted as standard and common practice? Are the two applications different because of versions of Codeigniter?
The standard of Code Igniter is to use those three folders:
Controllers
Models
Views
You can also create sub folders to better separate your files.
Searching a bit, I found that MyClientBase use something called codeigniter-modular-extensions-hmvc that is like a extension for CI.
Modular Extensions makes the CodeIgniter PHP framework modular.
Modules are groups of independent components, typically model,
controller and view, arranged in an application modules sub-directory,
that can be dropped into other CodeIgniter applications.
HMVC stands for Hierarchical Model View Controller.
I don't have experience with hmvc so I cannot tell you what is better. For the standard CI structure, try to separate well in sub-folders (controllers, views and models) related files and try to use helpers to better reuse your code when you need to use functions in more than one place.
I think MyClientBase (which seems to be far from the "standard" exemple), seems to be using HMVC more then MVC.

Resources