Welcome Guest, Not a member yet? Register   Sign In
How to extend a base class class library?
#7

[eluser]xadio[/eluser]
[strike]I have been working with Loader.php and there is nothing in Loader. This may be because
array class_parents( mixed $class [, bool $autoload ] )

is PHP5 specific. CI supports PHP4 so they aren't going to do that. The only thing close is
string get_parent_class( mixed $object )

You could extend the Loader.php:
/system/application/libraries/MY_Loader.php
Code:
class MY_Loader extends CI_Loader {
  function _ci_init_class($class, $prefix = '', $config = FALSE) {    
    // Is there an associated config file for this class?
    if ($config === NULL) {
      $config = NULL;
      if (file_exists(APPPATH.'config/'.$class.EXT)) {
        include(APPPATH.'config/'.$class.EXT);
      }
    }
        
    if ($prefix == '') {
      $name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class;
    } else {
      $name = $prefix.$class;
    }
        
    // Set the variable name we will assign the class to
    $class = strtolower($class);            
    $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class];

    // Require Parents
    foreach(class_parents($name, FALSE) as $parent) {
      //load the parents, but this will require a rewrite of _ci_load_class()
      $subclass = APPPATH.'libraries/'.config_item('subclass_prefix').$parent.EXT;
      $appfilepath = APPPATH.'libraries/'.$parent.EXT;
      $basefilepath = BASEPATH.'libraries/'.$parent.EXT;
      if(!in_array($subclass, $this->_ci_classes) &&
        (!in_array($appfilepath, $this->_ci_classes) ||
         !in_array($basefilepath, $this->_ci_classes)) {
        _ci_load_class($parent);
      }
    }

                
    // Instantiate the class        
    $CI =& get_instance();
    if ($config !== NULL) {
      $CI->$classvar = new $name($config);
    } else {        
      $CI->$classvar = new $name;
    }
  }
}

Haven't tested, but should work.[/strike]


Messages In This Thread
How to extend a base class class library? - by El Forum - 02-07-2008, 07:09 AM
How to extend a base class class library? - by El Forum - 02-07-2008, 11:44 AM
How to extend a base class class library? - by El Forum - 02-07-2008, 12:27 PM
How to extend a base class class library? - by El Forum - 02-07-2008, 12:32 PM
How to extend a base class class library? - by El Forum - 02-07-2008, 01:05 PM
How to extend a base class class library? - by El Forum - 02-07-2008, 04:21 PM
How to extend a base class class library? - by El Forum - 02-07-2008, 06:54 PM
How to extend a base class class library? - by El Forum - 02-08-2008, 01:42 PM



Theme © iAndrew 2016 - Forum software by © MyBB