• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
logging all user actions

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

#12
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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

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

#14
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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#15
(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.
Reply

#16
(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"
Reply

#17
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?

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply

#18
(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
Reply

#19
If he is running CodeIgniter 4 he can use Events. Events are like hooks in CI4.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.