• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
library classes

#11
[eluser]jaswinder_rana[/eluser]
Thanks Randy. Understood. Wasn't sure about this point.

#12
[eluser]sipsniffa[/eluser]
Many thanks Randy and jaswinder_rana for your help.

It turns out that the problems I experienced were related to the configuration option 'subclass_prefix'. I hadn't assigned any value to this variable (i.e. it was set to the empty string, '') and as a result the names of my library classes were deemed to be attempts to subclass CodeIgniter library classes (code snipped from _ci_load_class() in system/library/Loader.php):
Code:
$subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.EXT;

    // Is this a class extension request?            
    if (file_exists($subclass))
    {
        // ...
    }
There's potentially a logic error in this snippet. Whether the class being loaded ($class) is a subclass is established by adding the 'subclass_prefix' value and PHP extension and then checking whether that file exists on the file system. The test doesn't make sense when 'subclass_prefix' is the empty string.

[quote author="Randy Casburn" date="1229390515"]
Here is how CI determines the file name from the load->library call:

Code:
// We'll test for both lowercase and capitalized versions of the file name
foreach (array(ucfirst($class), strtolower($class)) as $class)

As you can see, there is no way the something like Special_Class will work.
[/quote]
I don't understand why your example wouldn't work, Randy. From my reading of the code, I think that capitalisation and underscores are fine, so long as the class and file names match (both in their use of case and underscores - strangely, the first character of the class/file name is allowed to vary).

I thought it worth pointing out these problems, as a forum search turned up a few other postings that appear to be related to the same issues.

[edit]
Submitted related post to Bug Reports forum.
[/edit]

Thanks again,

Paul.

#13
[eluser]sipsniffa[/eluser]
The 'subclass_prefix' configuration option takes a non-empty, default value of '_MY'. For newcomers to CI (such as me!) this is a clue that it shouldn't be assigned an empty value (see this bug report).

Paul.

#14
[eluser]Randy Casburn[/eluser]
[quote author="sipsniffa" date="1229448625"]so long as the class and file names match (both in their use of case and underscores - strangely, the first character of the class/file name is allowed to vary).[/quote]

Hey Paul,

yea...this wasn't always the case. I suppose this is old think on my part. I should update my thinking to the current revisions. I think it's probably been this way for a couple releases now.

I'm glad you're into the code base and poking around.

Sorry to have misled.

Randy

#15
[eluser]sipsniffa[/eluser]
[quote author="Randy Casburn" date="1229461366"][quote author="sipsniffa" date="1229448625"]
Sorry to have misled.
[/quote]

Not at all, Randy. I'm very grateful for the time and suggestions you (and jaswinder_rana) gave. We've all increased our understanding of CI!!

Cheers,

Paul.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.