Reputation: 10634
I have an app that uses HMVC and codeigniter. The entire app is in a git repo called MapIt-USA. I just ran into a scenario where i deployed this app to a client xyz and they wanted me to customize the front-end view layout. I made the modifications however, when i make backend controller, library, model patches/updates and i push these updates to origin and pull down from origin on the server I need a way to avoid overwriting those changes in the views.
Any ideas?
Upvotes: 0
Views: 77
Reputation: 102745
Basic idea for overloading views (or any file, really):
There will probably come a time when you have the need to overload or extend more than just views: maybe config files, helpers, language files, or even controllers. So, you might want to start thinking about how to deal with this in the long run. You can mimic the way CI works, looking in the system/
for files first, while allowing application/
files to extend or overload. Customizations of course would bear the burden of staying compatible.
Short example with views:
class MY_Template_Loader {
// We'll assume this is in your application/ dir
private $custom_path = 'custom_views/';
function load($file = NULL)
{
// This is the default view
$view = $file;
// Is there a file with the same name in the custom dir?
// If so, use that instead of the default
if (is_file(APPPATH.$this->custom_path.$file.'.php'))
{
// This is a little bit of a trick
// Use a relative path from CI's default view dir
$view = '../'.$this->custom_path.$file;
}
get_instance()->load->view($view);
}
}
Usage in a controller method:
function my_method()
{
$this->my_template_loader->load('my_method/index');
// If "APPPATH/custom_views/my_method/index.php" exists it will be loaded
// Otherwise it will try to load "views/my_method/index.php"
}
How you really do this is up to you, but that's the basic idea.
Upvotes: 1