Welcome Guest, Not a member yet? Register   Sign In
MY_Controller vs. Foo_Controller
#1

[eluser]pbarney[/eluser]
What is the functional difference between:

Code:
class MY_Controller extends Controller
...
class Admin_Controller extends MY_Controller

...and...

Code:
class LoginRequired_Controller extends Controller
...
class Admin_Controller extends LoginRequired_Controller

They're both extending "Controller", so what's the point of using MY_?

Thanks for any insight!

Peter
#2

[eluser]J Maxwell[/eluser]
CodeIgniter will automatically look for and load "MY_", although if you change the setting in the config file then you can get it to load "LoginRequired_" automatically instead? Although then all of your custom overrides to core libraries would have to be "LoginRequired".

If MY_ is bothering you, why not change it to "Site_" or "Wizard_" or something equally cool? Ahem.
#3

[eluser]pbarney[/eluser]
Ah, you've cleared it up. It's that "MY_" is autoloaded whereas the other is not. I don't have a problem with the prefix; I just didn't understand it's purpose.

Thanks!
#4

[eluser]J Maxwell[/eluser]
Hehe I did have a problem with the prefix, just sounded a little unprofessional in code that sometimes the client would see, so changed it to my company initials.

Glad to help,

John
#5

[eluser]pbarney[/eluser]
So a way around all this (if you don't mind PHP 5 compatibility) is to add an auto-load function to config.php:

Code:
/*
| -------------------------------------------------------------------
|  Native Auto-load
| -------------------------------------------------------------------
|
| Nothing to do with cnfig/autoload.php, this allows PHP autoload to work
| for base controllers and some third-party libraries.
|
*/
function __autoload($class)
{
if(strpos($class, 'CI_') !== 0)
{
  @include_once( APPPATH . 'libraries/'. $class . EXT );
}
}


Thanks to Phil Sturgeon, for this bit of usefulness.




Theme © iAndrew 2016 - Forum software by © MyBB