PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 19, 2022

[FIXED] logging activity to database yii framework

 March 19, 2022     logging, php, yii     No comments   

Issue

I'm using yii framework and I want to make an activity logging for every action that user do in my web. All of their activity will be saved to a table in database.

The things that will be recorded are:

  • user ID
  • table name (inserted, deleted, edited item)
  • time_action
  • activity (what did they do. ex: created project_name)

Please help. Thanks in advance.


Solution

I'm not sure what you are trying to do but is it like when a user deletes some item; then entry should be logged in database for that user? If yes, then you can create a common class and a static method in it like,

yourCommonClass::setActivityLog(user_id,activity_msg,time);

and put this code in every action that you have written. ex. actionUpdate, actionDelete.

  • you can get the user_id from Yii::app()->user->id
  • put you custom activity message like "User #user_id created new item" etc.
  • time you can get it while saving into database.

By the way, create a table and model for the same like ActivityLog. ;) This is what I did in my project.



Answered By - Onkar
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing