Welcome Guest, Not a member yet? Register   Sign In
Multi-level subfolders for controllers in CI 2.x
#10

[eluser]jjDeveloper[/eluser]
I came up with something nifty that works for me, feel free to try it out.

In your applications core library if you don't already have one add a subclass of CI_Loader and override the view function like so.

Code:
class MY_Loader extends CI_Loader {


    function view($view, $vars = array(), $return = FALSE)
     {
       $seg = explode('<>', $view);
       $out = '';
       $ct = 0;
       If($seg != FALSE) {
         foreach($seg as $dir) {
           switch($dir) {
            case 'f':
              $out .= 'forms/';
              break;
            case 't':
              $out .= 'template/';
              break;
            case 'r':
              $out .= 'registration/';
              break;
           }
           $ct++;
         }
         $view = $out . $seg[($ct - 1)];
       }
             return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
     }
}

To make this function work for your needs however you will have to add case statements for the sub-folders that you wish to abbreviate so to speak.

Lets say in your views you have a folder named content you would just add the following code to the switch statement.

Code:
case 'c':
              $out .= 'content/';
              break;

The resulting view calls to this folder can now be done using the following load call

Code:
$this->load->view('c<>some_content');

This will also work if you have multi-level sub-folders like this

Code:
$this->load->view('f<>r<>some_view');

This would have the same effect as doing this.

Code:
$this->load->view('forms/registration/some_view');


I find it helps code readability and also results in less typing when you wish to load views out of sub-folders. Keep in mind this addition will still retain the normal functionality if you load the view with its full path as well.

I just thought this might be something you may want to look at. I enjoy using it so hope someone else does too.

Cheers


Messages In This Thread
Multi-level subfolders for controllers in CI 2.x - by El Forum - 06-01-2011, 01:23 PM
Multi-level subfolders for controllers in CI 2.x - by El Forum - 06-02-2011, 10:52 PM
Multi-level subfolders for controllers in CI 2.x - by El Forum - 06-03-2011, 02:25 PM
Multi-level subfolders for controllers in CI 2.x - by El Forum - 06-03-2011, 03:22 PM
Multi-level subfolders for controllers in CI 2.x - by El Forum - 06-05-2011, 03:14 AM
Multi-level subfolders for controllers in CI 2.x - by El Forum - 06-05-2011, 03:34 AM
Multi-level subfolders for controllers in CI 2.x - by El Forum - 06-06-2011, 07:06 AM
Multi-level subfolders for controllers in CI 2.x - by El Forum - 06-06-2011, 07:08 AM
Multi-level subfolders for controllers in CI 2.x - by El Forum - 06-06-2011, 07:19 AM
Multi-level subfolders for controllers in CI 2.x - by El Forum - 01-24-2012, 06:04 PM
Multi-level subfolders for controllers in CI 2.x - by El Forum - 01-24-2012, 09:46 PM
Multi-level subfolders for controllers in CI 2.x - by El Forum - 12-27-2012, 01:53 AM
Multi-level subfolders for controllers in CI 2.x - by El Forum - 02-28-2013, 05:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB