Welcome Guest, Not a member yet? Register   Sign In
My problem with $this-load->whatever
#1

[eluser]marquex[/eluser]
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):

Code:
// 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:

Code:
foreach (array($class, ucfirst($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
#2

[eluser]Joshua Logsdon[/eluser]
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-gui...aries.html for info on extending/overriding native classes). I needed to do a similar thing to the router class and special url characters.
#3

[eluser]marquex[/eluser]
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!
#4

[eluser]Tom Schlick[/eluser]
because camelCase is stupid.
#5

[eluser]Joshua Logsdon[/eluser]
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.
#6

[eluser]marquex[/eluser]
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.




Theme © iAndrew 2016 - Forum software by © MyBB