EllisLab text mark
Advanced Search
     
My problem with $this-load->whatever
Posted: 24 January 2010 08:22 AM
Joined: 2010-01-14
6 posts

Hi,
I am developing my app on a windows system, and i made a personal library for user authentication in a file called trickyAuth.php

On windows everything is ok when loading it, but when i try the app on a linux system i get the error

Unable to load the requested class: trickyauth

I realized that the name of the library in the error message is in lower letters, so i had a look at the loader library and i see the next code in the _ci_load_class method (CI 1.7.2, Loader.php:751):

// We'll test for both lowercase and capitalized versions of the file name
        
foreach (array(ucfirst($class), strtolower($class)) as $class)
        
{
            $subclass 
APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.EXT;

            
// Is this a class extension request?            
            
if (file_exists($subclass))
            
{
                $baseclass 
BASEPATH.'libraries/'.ucfirst($class).EXT;
                
                if ( ! 
file_exists($baseclass))
                
{
                    log_message
('error'"Unable to load the requested class: ".$class);
                    
show_error("Unable to load the requested class: ".$class);
                

So codeigniter try to load the files when their name is in lower letters or with the first letter capitalized, but never “as it is”. In windows it’s ok because there’s no difference between capital and lower letters, but on linux my code just doesn’t work.

I’m aware about the naming convention used by codeigniter, but it would be easy to check if the file is named exactly like the parameter:

foreach (array($classucfirst($class), strtolower($class)) as $class

I’ll change my file name, but it’d be nice to add this to the next release of codeigniter

 
Posted: 24 January 2010 09:32 AM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2009-07-06
50 posts

Hi marquex. Good call, but I doubt that’s going to be in the next release. If you REALLY want to do this soon you will probably want to extend the loader class (bottom of http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html for info on extending/overriding native classes). I needed to do a similar thing to the router class and special url characters.

 
Posted: 24 January 2010 02:03 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2010-01-14
6 posts

Thanks Joshua,

Finally i changed the name of the file and all the calls to non capitalized letters. I’m trying to build something easy to install in any codeigniter but letting the people who install it have their class extensions.

I just wanted to tell about my problem to know if there is a reason for this restriction, it looks like something doesn’t let the files be called like myFiles.php so the use of my_files.php is mandatory.

I really hate underscores!

 
Posted: 24 January 2010 04:04 PM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2008-01-17
426 posts

because camelCase is stupid.

 Signature 

aka trs21219
CodeSanity | Github | LinkedIn | Facebook | Twitter | Last.fm

 
Posted: 24 January 2010 05:07 PM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2009-07-06
50 posts

Hi marquex, no problem.

Yeah I know what you mean. I had been following Java conventions for a while so it took a bit to get the hang of it. Now Codeigniter has a conventions/style guide in the user guide and that helped me see more of their approach.

 
Posted: 24 January 2010 05:30 PM   [ # 5 ]   [ Rating: 0 ]
Joined: 2010-01-14
6 posts

Yes i know about the style guide, but the fact of forcing the developer to follow the style guide has no style! smile

camelCase can be stupid, but people coming from java like me are used to it, why to forbid it?

I expected a more technical reason… anyway is a good reason.