Number in controller class name

#1
[eluser]BrianL[/eluser]
Hi,

My apologies if this has been posted before.

Was wondering if anyone came across this issue of using numbers in class names:

Try extending controller. Very simple stuff.

/system/application/libraries/MY_Controller0.php
Code:
<?php

class MY_Controller0 extends Controller {

    function MY_Controller0()
    {
        parent::Controller();
    }
    
}

?>

/system/application/controllers/Check.php
Code:
<?php

class Check extends MY_Controller0 {

    function Check()
    {
        parent::MY_Controller0();
    }

}

?>

Now it does not work with the number 0, or _0 and gives a PHP class not found error in the logs. But remove the zero, and it works.

Code:
[28-Jun-2010 19:22:59] PHP Fatal error:  Class 'MY_Controller0' not found in /system/application/controllers/Check.php on line 3

Tested on a fresh, clean install of CodeIgniter 1.7.2 and code cut and pasted. Simply delete the zeroes, and it works. Add in the zeroes and it does not (yes, there are zeroes in two places in Check.php and three places in MY_Controller0.php including the file name).

Also confirmed I have saved in correct file format UTF-8 without BOM with UNIX line returns, and uploaded in binary mode.

Please someone test this themselves, since it is driving me crazy Wink

#2
[eluser]vitoco[/eluser]
I think that the proper way to extend a CI BASE class is adding 'MY_' before the class name...so if you add any other string to end of the BASE name...doesn't work, cause in this case it search for MY_Controller ( MY_ + Controller ) ..not MY_Controller0.

One way to "fix" this is to include the MY_Controller0 class

Code:
include( '/system/application/libraries/MY_Controller0.php' );
..somewhere before the
Code:
class Check extends MY_Controller0 {

Saludos

#3
[eluser]BrianL[/eluser]
Very well, so you are saying I cannot name my classes MY_[any name I want] when I extend native libraries?

Thanks for answer!

EDIT: Yes I have confirmed this is the case, MY_Controller must extend Controller and no other name. How annoying, an entire day spent hunting for bugs and turns out to be this trivial matter heh heh.

#4
[eluser]InsiteFX[/eluser]
Not really see the link below!

Phil's Keeping It Dry Article

InsiteFX

#5
[eluser]BrianL[/eluser]
Hey Phil:

Thanks for link!

Workaround you're suggesting seems to be use MY_Controller extends Controller, then have more controllers extend MY_Controller. Which is fine by me!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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