Welcome Guest, Not a member yet? Register   Sign In
Extending a "standard" application with customer specific files
#1

[eluser]Jocke[/eluser]
Hello,

I have an application that I want to create a number of customer specific version of.

In my "corewebsite" I have the standard application and I'm wondering how to proceed if I would like to create a new version of this one with some new or changed files. Basicly I would want the "corewebsite" to act as a fallback for the customer applications to save me the trouble of updating all the customer sites when I do a change to the "corewebsite".

Quote:/www
system/
corewebsite/
...application/ <--- the "standard" application
...index.php
customer1website/
...customerspecific/ <--- only "new" or "changed" files
...index.php
customer2website/
...customerspecific/ <--- only "new" or "changed" files
...index.php

Anyone that have done something like this or if it's even possible without rewriting the whole framework? Smile

Thanks!
#2

[eluser]jjDeveloper[/eluser]
Try using GIT to implement version controll in your template application then you you can create branches for each instance all in one directory structure.

Then a GIT pull will update your application instances.

Just a thought
#3

[eluser]Jocke[/eluser]
[quote author="jjDeveloper" date="1327511184"]Try using GIT to implement version controll in your template application then you you can create branches for each instance all in one directory structure.

Then a GIT pull will update your application instances.

Just a thought[/quote]

Thanks for your idea but it's not viable for me. The whole idea is that I want to try to just have a single version of the "template" application files and not have to update the customer ones when I do a change in the "template" due to a significant number of customers.

Is there a way to do as I want?
#4

[eluser]Kamarg[/eluser]
It sounds like you're just looking to override certain parts of views but not the logic. If that's the case, you could try something like the below. This allows you to add multiple folders for CodeIgniter to look for views.
Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Loader extends CI_Loader
{
private $_view_paths;

function __construct()
    {
        parent::__construct();
  $this->_view_paths = array();
}

public function add_view_path($path)
{
  if(substr($path, -1) !== '/')
   $path = $path . '/';
  
  $new_path = $path;
  if(file_exists($new_path) && !in_array($new_path, $this->_view_paths))
  {
   $this->_view_paths[] = $new_path;
   return TRUE;
  }
  
  $new_path = APPPATH . $path;
  if(file_exists($new_path) && !in_array($new_path, $this->_view_paths))
  {
   $this->_view_paths[] = $new_path;
   return TRUE;
  }
  
  $new_path = APPPATH . 'views/' . $path;
  if(file_exists($new_path) && !in_array($new_path, $this->_view_paths))
  {
   $this->_view_paths[] = $new_path;
   return TRUE;
  }
  
  return FALSE;
}

/**
  * Load View
  *
  * This function is used to load a "view" file.  It has three parameters:
  *
  * 1. The name of the "view" file to be included.
  * 2. An associative array of data to be extracted for use in the view.
  * 3. TRUE/FALSE - whether to return the data or load it.  In
  * some cases it's advantageous to be able to return data so that
  * a developer can process it in some way.
  *
  * @access public
  * @param string
  * @param array
  * @param bool
  * @return void
  */
function view($view, $vars = array(), $return = FALSE)
{
  foreach($this->_view_paths as $path)
  {
   if(file_exists($path . $view . EXT))
   {
    return $this->_ci_load(array('_ci_view' => $path . $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return, '_ci_path' => $path . $view . EXT));
   }
  }
  
  return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
}
}

Then in your controller/MY_Controller you just have to do
Code:
$this->load->add_view_path('path_to_customer_views');

Hope that helps.
#5

[eluser]jjDeveloper[/eluser]
<a href="http://ellislab.com/codeigniter/user-guide/general/cli.html">running codeigniter from command line interface</a>

Build yoursel a little tool with this method maybe
#6

[eluser]Jocke[/eluser]
Let me rephrase the problem a bit. What I want really is to add another folder (outside of the application folder) to be looked in for helpers, controllers, libs and so on.

Out of the box CI looks for extended classes in the application folder but I would want it to look in another folder as well.

Quote:templateapp/
...application/
......controllers/
......helpers/
......etc
customer1/
...customerspecific/
......controllers/
......helpers/
......etc

I can define a path in the index.php file for each customer that points to the customerspecific folder but it seems rather hard to extend the loader (and I believe some other classes as well).
#7

[eluser]CroNiX[/eluser]
Sounds like a good candidate for "application packages". Look towards the bottom of the page for the load class. Never tried using it, though.

If that doesn't work, you would probably have to extend the load class to search in your additional directories.
#8

[eluser]jjDeveloper[/eluser]
<a href="http://getsparks.org/">Codeigniter Sparks</a> is an awesome way to use packages but you would have a slight learning curve to make one.




Theme © iAndrew 2016 - Forum software by © MyBB