Multiple controllers simultaneously?

Coolfactor summarizes the overall problem.

You need to add third party support for blocks in order to make this work. A block would be an entity that is loaded in a template (or master view) with its own dedicated controller and model code. There are numerous threads about creating blocks using a partial view in combination with a helper. The helper handles the controller and business logic (model) code.

This actually works very well with Coolfactor's proposed View library for CI in combination with some block support ideas discussed in the Modular Separation thread and other threads. CI and the View library make no distinction between the various flavors of views that might exist. To treat blocks as separate entities in CI, additional search paths are added to an extended version of the Loader library and the view method is overloaded to search additional paths for other flavors of views such as blocks, components (wrapped form elements, trees, accordians, grids, etc.) or templates. The distinction between various view types is made based on where the view is stored. The caveat is that all views, regardless of their flavor, need unique names. Below is an overloaded view method for modular separation v1.0 (will not work with 2.x yet) that allows module views, block views, and templates to be loaded from separate directory structures.

function view($view, $vars = array(), $return = false)
        $module = '';
        $CI = &get;_instance();

        // Is the requested view a module view?
        if (is_dir(APPPATH . 'modules/' . $CI->uri->segment(1))) {
            $module = $CI->uri->segment(1);

        // Is the requested view a module view in a sub-folder?
        if (is_dir(APPPATH . 'modules/' . $CI->uri->segment(2) . '/modules/' . $CI->uri->segment(1))) {
            $module = $CI->uri->segment(2);

        // Make the request a module view
        if (file_exists(APPPATH . 'modules/' . $module . '/views/' . $view . EXT)) {
            $view = '../modules/' . $module . '/views/' . $view;

        // Make the request a template view
        if (file_exists(APPPATH . 'templates/' . $view . '/' . $view . EXT)) {
            $view = '../templates/' . $view . '/' . $view;

        // Make the request a block view
        if (file_exists(APPPATH . 'blocks/' . $view . '/' . $view . EXT)) {
            $view = '../blocks/' . $view . '/' . $view;

        return parent::view($view, $vars, $return);

If you don't need modular separation (CMF-like infrastructure), the above approach can be modified to use blocks with the standard MVC directory structure. With the above, you would add three new directories to application/ called modules, blocks, and templates. Support for the original MVC directory structure remains, so controllers, models, and views could be loaded like normal if they were not stored in the three new directory hierarchies.

The above approach is not the only approach to handling this problem. There are other solutions discussed in various threads. I believe that Rick Jolly started the most recent thread on this topic a few weeks ago.

Fairly shortly, you should see a better approach based on the use of a Block controller in conjunction with an extended version of CF's View library and the Modular Separation extensions. It should be possible to modify that approach to work with the standard MVC directory structure. This approach allows the module, block, and template entity names and directory names to be changed from a config file. Once the current refactoring of modular separation v2.x is completed, you should see a solution shortly afterwards.

Messages In This Thread
Multiple controllers simultaneously? - by El Forum - 09-08-2007, 05:37 AM
Multiple controllers simultaneously? - by El Forum - 09-08-2007, 06:18 AM
Multiple controllers simultaneously? - by El Forum - 09-08-2007, 08:38 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.