Welcome Guest, Not a member yet? Register   Sign In
extendible controllers and models
#1

[eluser]Lotti[/eluser]
Hi everybody!

We (developers of a webagency) are trying to use CI to develop our systems (CMS, ecommerce) and we wanted to add a nice feature that will save us a lot of time.

Let me clearly explain what we need:
- we want to keep the "base" code (i mean "the original code of our CMS") separated from the various customization for customers.
- the customization file could not exists.
- every hack must be inside application folder.

I'm quite expert with codeigniter and i alreday hacked the router class, but i don't like it so much. I need your opinion.

Actually, my hacks works like this:

Directory structure
Quote:application/controllers/CMS/ --> here we want to keep the original CMS controllers
application/controllers/Ecommerce/ here we want to keep the original Ecommerce controllers
application/controllers/* --> here we want to put the customer customization
a similar pattern could be used for models too (i haven't hacked models loading yet)

then, my controllers will be:
Quote:application/controllers/CMS/cms_page.php --> father class
application/controllers/page_cms.php --> child class

then inside the routing config file i have to write the "default behaviour" for each controller, e.g.:
Code:
$route['page'] = "cms/cms_page";

Then i hacked the Router CI class like this, overloading _validate_request with a check for a customization class between the search in root folder and in sub-folder. The algorithms simply checks the existence of "page_cms.php" in the root and call it instead of call CMS/cms_page.php
Code:
....
//before this line the root check ends

$x[1] = str_replace($x[0].'_','',$x[1]);
$x[1] .= '_'.$x[0];
if (file_exists(APPPATH.'controllers/'.$x[1].'.php'))
{
$x = array_slice($x, 1);
$this->set_directory('');
$this->set_class($x[0]);
$this->set_method(isset($x[1]) ? $x[1] : 'index');
return $x;
}

//down here the sub-folder check starts
....


What i don't like of my solution is that i have to write a the "default behaviour" for each controller inside application/config/routers.php. Maybe an easier solution to this problem will be just to use an unique identificator (like CI does with MY_) instead of CMS and Ecommerce.

Do you have any better idea or already solved something like this?

Thank you.
#2

[eluser]Lotti[/eluser]
an answer like: "it already exists a php framework that does what you need" would be appreciated too!
#3

[eluser]porquero[/eluser]
For extend CI you have various alternatives:

- Creating libraries
- "Extending" Helpers
- Using Hooks for extend core


Also I recomend use HMVC plugin. You'll can manage applications better.

There are more ways to customize CI. You can find in user guide.

I hope help you.




Theme © iAndrew 2016 - Forum software by © MyBB