Frontend and Backend (Base controllers) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Frontend and Backend (Base controllers) (/showthread.php?tid=56794) Pages:
1
2
|
Frontend and Backend (Base controllers) - El Forum - 01-20-2013 [eluser]cPage[/eluser] Is it ok to put this code in config.php ? Code: function __autoload($classname) I saw this little hack in a tutorial about managing Frontend_controller and Backend_controller. Quote:CI_Controller I tried to skip the function of the config file by adding those 2 controllers to the autoload array without success, and then i understood that MY_ is the only way, that i can implent my own libraires, or this code in config.php. It would be nice if CI add something else than MY_ other options like Frontend or Backend . Is there something more appropriate for Frontend and Backend supports? Frontend and Backend (Base controllers) - El Forum - 01-20-2013 [eluser]xtremer360[/eluser] Nope. That works just fine. I use that for my applications. Frontend and Backend (Base controllers) - El Forum - 01-20-2013 [eluser]Aken[/eluser] What exactly is the point of this autoload? If you're just trying to create two different base controllers, you can do that just fine inside a single MY_Controller.php file. You don't have to name the class MY_Controller, so long as the filename is named as such. You could have 10 different base classes in there if you wanted. Frontend and Backend (Base controllers) - El Forum - 01-21-2013 [eluser]cPage[/eluser] [quote author="Aken" date="1358747741"]What exactly is the point of this autoload? If you're just trying to create two different base controllers, you can do that just fine inside a single MY_Controller.php file. You don't have to name the class MY_Controller, so long as the filename is named as such. You could have 10 different base classes in there if you wanted.[/quote] To keep the code DRY. By this way all common functions for both backend and frontend will be in MY_ . Frontend and Backend (Base controllers) - El Forum - 01-21-2013 [eluser]PhilTem[/eluser] Nope, that's not what @Aken suggested. He was suggesting to create a file MY_Controller, which holds multiple classes e.g. Code: <?php That's got nothing to do with DRY code, it's even better than having let's say 20 class files in APPPATH . 'core/' The advantage of this over the __autoload function: Once the MY_Controller file got included by the Loader class, all other classes can be instantiated easily and directly without even using a __autoload function thus kinda speeding up the application, as well Frontend and Backend (Base controllers) - El Forum - 01-21-2013 [eluser]cPage[/eluser] Quote:That's got nothing to do with DRY code, it's even better than having let's say 20 class files in APPPATH . 'core/' Where do you see 20 class files in the above pattern ? There's only 1 in core/MY_Controller Other files are in libraries. But i got the point anyway, thanks. Frontend and Backend (Base controllers) - El Forum - 01-21-2013 [eluser]Aken[/eluser] If you're only loading a single MY_Controller core file, and the rest are libraries, then I really don't see the need for the autoload. Libraries are loaded via the Loader class already. The only way you'd need autoloading is if you wanted to use the "new Class()" instantiation method, which is completely unrelated to base MY_Controller... Frontend and Backend (Base controllers) - El Forum - 01-21-2013 [eluser]cPage[/eluser] [quote author="Aken" date="1358812731"]If you're only loading a single MY_Controller core file, and the rest are libraries, then I really don't see the need for the autoload. Libraries are loaded via the Loader class already. The only way you'd need autoloading is if you wanted to use the "new Class()" instantiation method, which is completely unrelated to base MY_Controller...[/quote] Because you can't extend the base MY_Controller into libraries like this : Code: class Frontend extends MY_Controller { ... } without using the autoload in the config file. I think it depends on what you can stand. I can't stand many classes in 1 file. But i can stand a simple function() in config file, that gives the choice to put every base classes into librairies/ . And using a powerful child such as : Code: admin extends Admin_Controller() Frontend and Backend (Base controllers) - El Forum - 01-21-2013 [eluser]Aken[/eluser] [quote author="cPage" date="1358816404"]Because you can't extend the base MY_Controller into libraries like this : Code: class Frontend extends MY_Controller { ... } I don't know if you're confusing terminology, but you never want libraries to extend a controller class. If you want to avoid multiple classes in the same file, then just use normal php and include/require the files from your MY_Controller.php file. There is no reason to create an autoload and potentially add problems to your code in the future so you can support two files, when you can just toss in some normal PHP. Frontend and Backend (Base controllers) - El Forum - 01-21-2013 [eluser]cPage[/eluser] Tuts+ |