MY_Controller |
[eluser]blasto333[/eluser]
Is it necessary to have all Controllers that override Controller in application/libraries/MY_Controller.php? I know this way they will be autoloaded, but what is the harm in doing this: Currently in MY_Controller I have this: class Secure_Area extends Controller { .. .. .. } abstract class Person_Controller extends Secure_Area implements iPerson_Controller { .. .. .. } For readability I would rather have two separate files: libraries/Secure_Area.php libraries/Person_Controller.php
[eluser]blasto333[/eluser]
I just ended up making separate files and then doing a require_once inside MY_Controller.php
[eluser]Frank Berger[/eluser]
you should seriously consider to read and understand CI's documentation. You don't need a MY_controller at all unless you want to extend the controller class in general. All your controller files go into /application/controllers/ and do not need a special include or any other stuff like that. Read this chapter and all its sub-chapters in the documentation: http://ellislab.com/codeigniter/user-gui...llers.html Frank
[eluser]blasto333[/eluser]
I have read it, I am extending the controller class in general, thats why they were in MY_Controller.php to begin with. The controller classes in this file are not used in the application as a normal controller would. These are just base controller classes that the real controllers extend. It might make more sense if I show you the full code: MY_Controller.php Code: <?php Secure_Area.php Code: <?php Person_Controller.php Code: <?php
[eluser]Frank Berger[/eluser]
ok, makes more sense now. I had/have the same problem with the phpgACL implementation i posted in the forum here as well. The problem is that the autoload comes too late. You're right in this case a my_controller with an include is my 'cheap' alternative as well. The only other option you have is to look into the hook functionality. There you can execute commands very early in CI's life-cycle, and within such a function you can include a custom controller class as well (or more than one) hope that helps Frank
[eluser]Rick Jolly[/eluser]
In the name of transparency, I just require/include parent classes in the child class. It's self documenting. I don't use MY_Controller because, as you wrote, if you want more than one parent controller, you have to hide them away in the same file. Alternatively, if using class naming conventions, you could write a simple php 5 __autoload() function.
[eluser]blasto333[/eluser]
Thats what I ended up doing, but didn't use __autoload as I think being verbose and transparent makes it a lot easier to understand. (Just like you said) [quote author="Rick Jolly" date="1224452562"]In the name of transparency, I just require/include parent classes in the child class. It's self documenting. I don't use MY_Controller because, as you wrote, if you want more than one parent controller, you have to hide them away in the same file. Alternatively, if using class naming conventions, you could write a simple php 5 __autoload() function.[/quote] |
Welcome Guest, Not a member yet? Register Sign In |