Welcome Guest, Not a member yet? Register   Sign In
MY_Loader.php HMVC Modules Change View Paths
#1

(This post was last modified: 12-14-2015, 08:35 PM by wolfgang1983.)

I though I might post this code if any one uses HMVC.

I the code below I have added a glob function for a MY_Loader.php

Where symbol * in glob means the module name


PHP Code:
// Modules
$module_view_paths glob(APPPATH 'modules/*/views/template/'GLOB_ONLYDIR);

foreach (
$module_view_paths as $module_view_path) {
 
 $this->_ci_view_paths = array(
 
   $module_view_path => TRUE
  
);



So what this means instead of doing

PHP Code:
$this->load->view('template/folder/view_name'); 


All you need to do is


PHP Code:
$this->load->view('folder/view_name'); 


Here is the full MY_Loader.php


PHP Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

/* load the MX_Loader class */
require APPPATH."third_party/MX/Loader.php";

class 
MY_Loader extends MX_Loader {
 
   
    
public function __construct() {

 
       $this->_ci_ob_level  ob_get_level();

 
       // Default
 
       $this->_ci_view_paths = array(
 
           APPPATH 'views/' => TRUE
        
);

 
       // Modules
 
       $module_view_paths glob(APPPATH 'modules/*/views/template/'GLOB_ONLYDIR);

 
       foreach ($module_view_paths as $module_view_path) {
 
           $this->_ci_view_paths = array(
 
               $module_view_path => TRUE
            
);
 
       }

 
       $this->_ci_library_paths = array(APPPATHBASEPATH);

 
       $this->_ci_model_paths = array(APPPATH);

 
       $this->_ci_helper_paths = array(APPPATHBASEPATH);

 
       log_message('debug'"Loader Class Initialized");

 
   }



Attached Files
.php   MY_Loader.php (Size: 931 bytes / Downloads: 123)
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB