Welcome Guest, Not a member yet? Register   Sign In
how to create log activities
#1

[eluser]my9006ci[/eluser]
this month,
i want to study about log activities for my codeigniter project
so,...
where I should start??
please help me to learn about log activities like facebook activities?
please put reference
#2

[eluser]JoostV[/eluser]
You need two tables: one for users and one for logs.
Create a logger model with a method that saves a message to the log table. Make sure you know the user's ID!
Code:
function write($user_id, $message) {

    if(intval($user_id) == 0) { // invalid user
        return false;
    }

    $data['message'] = $message;
    $data['user_id'] = intval($user_id);
    $data['datetime'] = date('Y-m-d H:i:s');
    $this->db->insert($data);
}

Call that method every time you wish to log a user action
Code:
$this->load->model('logger');
$this->logger->write($this->session->userdata('user_id'), 'User did something awful in file ' . __FILE__ . ' on line '. __LINE__);
#3

[eluser]my9006ci[/eluser]
ok JoostV, thanks for info...
i try...
thanks again...
#4

[eluser]my9006ci[/eluser]
hy JoostV...
i have 2 question for you
1. code __FILE__ for what?
2. code __LINE__ for what?
#5

[eluser]digitalbloke[/eluser]
Hi my9006ci

PHP will automatically replace __FILE__ and __LINE__ and the filename that called $this->logger->write, and the line number where $this->logger->write was called.

So the final message logged in your database might look something like:

User did something awful in file /home/www/system/application/controllers/welcome.php on line 12

Hope this helps.
#6

[eluser]my9006ci[/eluser]
thanks digitalbloke




Theme © iAndrew 2016 - Forum software by © MyBB