Controller + Model vs Ultra-slim controller that barely does anything + Library |
08-19-2016, 10:15 AM
(This post was last modified: 08-19-2016, 10:29 AM by PaulD. Edit Reason: Added PPPPS )
There are lots of different ways you can do this. I would do this:
First you need at least two tables, one for actions, and then one for action_log Code: actions Then a library for logging actions. Something to use like this: PHP Code: public function log_action($action_code, $user_id) { As for redirects or flash messages or how you deal with a certain circumstance, that is entirely separate from the action logs and should not be part of the action logging. I would autoload the action library, and then you are free to call it from wherever you need to. But if you really want to directly couple it together, you could add a column or two to the action table, one to indicate a logout url to implement a redirect, one to indicate a message field for a standard message to be returned. Or, you can add to the library with a set method something like: PHP Code: $this->login_library->set_redirect('my/link'); Or just put it into the call PHP Code: $this->login_library->log_action($action_code, $user_id, 'my/link', 'You are not allowed to do that.'); It really all depends on your app design and how you are implementing your messages/notifications etc. For instance, in your common header file you might have a: PHP Code: <?php if (!empty($notification)) { ?> Hope that helps in some way Paul. PS In terms of guests, you can set the user_id to 0, which could, for example, return the notificatons as per normal but not log in the database the actions done. PPS Since notifications would be pretty standard piece of js, it would be in your site.js loaded on every page. Even if not used, it is a few lines at most. PPPS You definitely do not need an entire module for this. But if you are into HMVC, then I suppose you should do a notifications module rather than a library. PPPPS (Last one) - It does not matter how tiny a module or a library or a model is. It is about the right place to put it to keep your site consistently built. Even if a model has a single database call in it, if it serves for proper seperation of concerns, you should do it. It will almost certainly fill up later as other functions pop up as being needed. And even if not, it still makes sense to keep to whatever pattern you are using. |
Welcome Guest, Not a member yet? Register Sign In |