Part of the EllisLab Network
   
 
[PATCH INCLUDED] loading classes from subdirectory
Posted: 12 February 2007 02:11 PM   [ Ignore ]  
Summer Student
Total Posts:  4
Joined  01-11-2007

In some cases it is necessary to share code and using seperate directories especially while connecting code from different locations via svn:external property.

My problem was, that the classes are not loaded.

I fixed it an would like to give you the patch. (changed Loader.php)

aim is to provide possibilities:

$this->load->library('ext_xpath/xpath');

patch is about 11 lines ( mainly replacements )

the essentials:

diff—normal old_Loader.php new_Loader.php
680c680,689
<
—-
>
>          /**
>          * add support for classes with paths
>          */
>          $class_dir = dirname( $class );
>          if ( strlen($class_dir) > 0 )
>          {
>                $class = str_replace($class_dir.’/’,’‘,$class);
>          }
>
683a693
>                $class_path = ‘libraries/’.$class_dir.’/’;
685c695
<                if (file_exists(APPPATH.‘libraries/’.config_item(‘subclass_prefix’).$class.EXT))
—-
>                if (file_exists(APPPATH.$class_path.config_item(‘subclass_prefix’).$class.EXT))
687c697
<                    if ( ! file_exists(BASEPATH.‘libraries/’.ucfirst($class).EXT))
—-
>                    if ( ! file_exists(BASEPATH.$class_path.ucfirst($class).EXT))
693,694c703,704
<                    include(BASEPATH.‘libraries/’.ucfirst($class).EXT);
<                    include(APPPATH.‘libraries/’.config_item(‘subclass_prefix’).$class.EXT);
—-
>                    include(BASEPATH.$class_path.ucfirst($class).EXT);
>                    include(APPPATH.$class_path.config_item(‘subclass_prefix’).$class.EXT);
704c714
<                    $fp = $path.‘libraries/’.$class.EXT;
—-
>                    $fp = $path.$class_path.$class.EXT;

diff -c old_Loader.php new_Loader.php

*** old_Loader.php    2007-02-12 19:15:51.041504304 +0100
--- new_Loader.php    2007-02-12 19:14:44.000000000 +0100
***************
***
677,697 ****
      
{    
          
// Get the class name
          
$class = str_replace(EXT, '', $class);
!
          
// We'll test for both lowercase and capitalized versions of the file name
          
foreach (array(ucfirst($class), strtolower($class)) as $class)
          
{
              
// Is this a class extension request?
!             if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT))
              
{
!                 if ( ! file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT))
                  
{
                      log_message
('error', "Unable to load the requested class: ".$class);
                      
show_error("Unable to load the requested class: ".$class);
                  
}
      
!                 include(BASEPATH.'libraries/'.ucfirst($class).EXT);
!                 include(
APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT);
      
                  return
$this->_ci_init_class($class, config_item('subclass_prefix'), $params);            
              
}
--- 677,707 ----
      
{    
          
// Get the class name
          
$class = str_replace(EXT, '', $class);
!         
!         
/**
!          * add support for classes with paths
!          */
!         $class_dir = dirname( $class );
!         if (
strlen($class_dir) > 0 )
!         
{
!             $class = str_replace($class_dir.'/','',$class);
!         
}        
!         
          
// We'll test for both lowercase and capitalized versions of the file name
          
foreach (array(ucfirst($class), strtolower($class)) as $class)
          
{
+             $class_path = 'libraries/'.$class_dir.'/';
              
// Is this a class extension request?
!             if (file_exists(APPPATH.$class_path.config_item('subclass_prefix').$class.EXT))
              
{
!                 if ( ! file_exists(BASEPATH.$class_path.ucfirst($class).EXT))
                  
{
                      log_message
('error', "Unable to load the requested class: ".$class);
                      
show_error("Unable to load the requested class: ".$class);
                  
}
      
!                 include(BASEPATH.$class_path.ucfirst($class).EXT);
!                 include(
APPPATH.$class_path.config_item('subclass_prefix').$class.EXT);
      
                  return
$this->_ci_init_class($class, config_item('subclass_prefix'), $params);            
              
}
***************
***
701,707 ****
              for (
$i = 1; $i < 3; $i++)
              
{
                  $path
= ($i % 2) ? APPPATH : BASEPATH;    
!                 
$fp = $path.'libraries/'.$class.EXT;
                  
                  
// Does the file exist?  No?  Bummer...
                  
if ( ! file_exists($fp))
---
711,717 ----
              for (
$i = 1; $i < 3; $i++)
              
{
                  $path
= ($i % 2) ? APPPATH : BASEPATH;    
!                 
$fp = $path.$class_path.$class.EXT;
                  
                  
// Does the file exist?  No?  Bummer...
                  
if ( ! file_exists($fp))

hope you will add this in your next release

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 66412 Total Logged-in Users: 25
Total Topics: 84753 Total Anonymous Users: 0
Total Replies: 454814 Total Guests: 242
Total Posts: 539567    
Members ( View Memberlist )
Newest Members:  NirCalexmuellerkizerdrixcaptainredmuffquinodligtharttechsivamDjordjesammozzazodman23