Welcome Guest, Not a member yet? Register   Sign In
Controller + Model vs Ultra-slim controller that barely does anything + Library
#2

(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
-------
 action_id        
 action_name    // ie logout, login, not allowed, whatever
 action_code    // for convenience so logout = LO, login=LI etc (unique)

action log
----------
 log_id
 log_action_id
 log_date
 log_user_id

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');
$this->login_library->set_message('You are not allowed to do that.');
$this->login_library->log_action($action_code$user_id); 

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)) { ?>
   ... show notification html absolutely positioned on page at top right or something
<?php ?>
And your action log would return a suitably formatted notification. You could even, in your actions table, indicate if an action should send a red error message, a blue info message, or a green success message, etc etc.

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.
Reply


Messages In This Thread
RE: Controller + Model vs Ultra-slim controller that barely does anything + Library - by PaulD - 08-19-2016, 10:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB