Reputation: 24122
I am creating a management/crm system.
I have a class in my libs folder called Util which contains some static functions.
I want to create a static function for logging user actions from anywhere in my system i.e.
Util::log($userId, $action) ;
The bit that has me wondering is how should I pass this data to my database as I would need to instantiate my database class which is contained in a class called Model in my libs folder.
What is the smoothest way to do this?
Would it be better to simply create a log class in my controllers folder and have it interface with its own logModel class the same way as all my other non lib controllers do?
Upvotes: 1
Views: 479
Reputation: 331
Besides having a static method that let's you call your logging from anywhere i think that if the log table is in the db it's part of the model, so the application must declare a log class wich maps the log instances in the application and the logModel to manage these instances.
I suppose that the static method must contain only this few rows of code
$l = new Log();
$l->setUserId($userId);
$l->setAction($action);
$lm = new logModel();
$lm->save($l);
so the utility of having it is just to not repeat the above code in all parts of the application.
Upvotes: 1