Welcome Guest, Not a member yet? Register   Sign In
Writing Admin/User/Public controllers to insure authentication

(12-23-2014, 10:27 AM)sneakyimp Wrote:
(12-23-2014, 04:40 AM)Avenirer Wrote: Well... If you are talking about best practices, the best practice would be to have only a MY_Controller. If you are talking about your needs and how you see it easier to implement them your application, CodeIgniter is basic enough to allow you to do whatever you want and make it as complex as you want, if you know how. Smile
Avenirer, I'm guessing that's your article? It's nice. I'm inclined to trust you but just want to be sure. Perhaps you could more specifically address this question that I asked:

\sneakyimp Wrote:I'm wondering if using hooks as described in the article is in fact the recommended way to go.
There seem to be many ways to accomplish something in CI. I'm primarily interested in avoiding techniques that require special effort every time I have to upgrade CI to the next version. With that in mind, putting my custom code in files that are not touched by the CI devs seems very important to me. I would also agree that putting a lot of code in a configuration file seems like a bad idea. Perhaps you could explain why you think using hooks is the best approach. Is this code safe from a CI core upgrade?

As for my plan to use more than one controller, it seems pretty apparent to me that my site is likely to have session-related functionality whether visitors are logged in or not. It further seems likely that I'll have distinct functionality for administrators versus visiting authenticated users. I expect Admin_Controller to inherit from User_Controller which will inherit in turn from Basic_Controller (or something like that). If anyone thinks this is a bad idea, I'd love to know why. It seems like essentially the same thing recommended in Avenirer's article...

I also like Hobbes' suggestion of putting some code after the class definition to load the Admin_Controller (and possibly other classes). This seems simpler to me than creating an entirely separate hook and enabling hooks, etc. It has the additional advantage that it doesn't require me to alter files distributed as part of CI.

In my opinion, putting an autoload inside... wherever (some people put it into config, some people put it into main index.php)... is  a bit hack'ish... That is because, after you've done that you may have forgotten where you've put it.

Hobbes' suggestion is no better than the first method, that is because is not a good practice, you simply put the autoload inside a MY_Controller.

On the other hand we have the hooking system which, logically seems better than the first options. That is because we establish an order of loading the classes, and also we know from the start where to look for the autoloader.

Another method, which I think would be the best but I didn't have the time to look into (that is "I don't know yet how to implement"...) would be to use the Composer and then use namespacing when defining and asking for the necessary controller.

Messages In This Thread
RE: Writing Admin/User/Public controllers to insure authentication - by Avenirer - 12-23-2014, 05:07 PM

Theme © iAndrew 2016 - Forum software by © MyBB