CodeIgniter Forums
logging all user actions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: logging all user actions (/showthread.php?tid=77436)

Pages: 1 2


RE: logging all user actions - Goddard - 09-02-2020

I am using CI 3. In CI 3 all the models use either $this->db->query, $this->db->insert, $this->db->update, or $this->db->delete.

Sorry I am not understanding what you mean by just put it in MY_Model. Put everything in how?

Thanks for elaborating.


RE: logging all user actions - InsiteFX - 09-03-2020

You create a MY_Model in ./application/core/MY_Model.php which extends CodeIgniters CI_Model.

Now you add all your own methods that you want to reuse to the MY_Model.

You then extend all of your new models form the MY_Model.


RE: logging all user actions - Goddard - 09-03-2020

This requires modifying all 150 models that already exist.

This also ignores the fact many of the models may have different named functions for different operations.

Am I missing something, but what you said still isn't enough information.

This is an existing project and not a new project.


RE: logging all user actions - InsiteFX - 09-03-2020

Then all I can say is that the project was not scoped out in the beginning the correct way.

You only have to options the one you talk about or a new MY_Model.

You would only need to do a search and replace on 150 models using search for extend CI_Model
and replace with MY_Model.

Or your way try to hack the CI query which if you read up on it the database is not extendable.


RE: logging all user actions - Omar Crespo - 09-05-2020

(09-03-2020, 05:02 AM)Goddard Wrote: This is an existing project and not a new project.

Then in that project whas not used the software engineering or the OOP Paradig. Or something in the process went wrong. If you give me an email I'll send you an example, so you can see how works the observer pattern and the Object Oriented Programing in CodeIgniter 3.


RE: logging all user actions - T.O.M. - 09-14-2020

(09-01-2020, 01:11 PM)Goddard Wrote: I am using CI 3.  I want to log all users insert, update, and delete to a specific table in my database.  Can I easily do this using MY_Model, or some other way?

You can do this with hooks - you need "post_controller" hook.
In your hook method you just need to do:

PHP Code:
$CI =& get_instance(); // use codeigniter functions
$CI->load->database();
$CI->db->queries;  // <-- get all queries executed by controller, this is what you need 

"$CI->db->queries" contains an array of all executed db queries when controller was processed.
You can also get executing time of all queries with "$CI->db->query_times"


RE: logging all user actions - nc03061981 - 09-14-2020

I have one idea
1. Save user actions in text file (create a helper function to save actions to text file: helper_logs_user_actions($user, $action) and call when user have action
2. Using Cronjob save from text file to database after 1 hour, 2 hours... belong to  num rows,...
Can or not?


RE: logging all user actions - Goddard - 09-28-2020

(09-14-2020, 01:58 PM)T.O.M. Wrote:
(09-01-2020, 01:11 PM)Goddard Wrote: I am using CI 3.  I want to log all users insert, update, and delete to a specific table in my database.  Can I easily do this using MY_Model, or some other way?

You can do this with hooks - you need "post_controller" hook.
In your hook method you just need to do:

PHP Code:
$CI =& get_instance(); // use codeigniter functions
$CI->load->database();
$CI->db->queries;  // <-- get all queries executed by controller, this is what you need 

"$CI->db->queries" contains an array of all executed db queries when controller was processed.
You can also get executing time of all queries with "$CI->db->query_times"

Great suggestion.  This is a great option.

Thanks


RE: logging all user actions - InsiteFX - 09-28-2020

If he is running CodeIgniter 4 he can use Events. Events are like hooks in CI4.