Clarification about MY_Controller and relative inheritances |
(04-18-2017, 04:31 PM)marksman Wrote: It will do the job, but I don't think it's the best practice. Once again I do not understand the above statement. The pronoun's antecedent is vague in the extreme. To put that more clearly, what the heck is the "it" you're talking about? marksman Wrote:Or simply use the framework's convention to autoload your files.As I pointed out, the framework's "convention to autoload" design is not always adequate. For instance, consider two custom libraries. File: application/libraries/CustomLib1.php PHP Code: class CustomLib1 And a second class that extends CustomLib1 File: application/libraries/CustomLib2.php PHP Code: class CustomLib2 extends CustomLib1 If you're relying on the framework's "convention to autoload" and make the following call PHP Code: $this->load->library('CustomLib2'); You will receive a fatal error stating that Class 'CustomLib1' cannot be found. To overcome this problem you have a couple options. First option: Manually include the base class file before trying to load the child class. PHP Code: include APPPATH . 'libraries/CustomLib1.php'; Second option: Implement an autoloader. The second option is what I prefer. I'm happy to hear that you know spl_autoload_register is used to implement an autoloader. ![]() |
Welcome Guest, Not a member yet? Register Sign In |