tattersoftware / codeigniter4-audits

Lightweight object logging for CodeIgniter 4
MIT License
13 stars 6 forks source link

Not Working #13

Closed takerukimura closed 2 years ago

takerukimura commented 2 years ago

Hi there. I already followed all the installation steps using composer. the database table 'audits' already inside my database. And I already add this code in one of my Model : `<?php

namespace App\Models;

use CodeIgniter\Model;

class accesslevel_mst extends Model { use \Tatter\Audits\Traits\AuditsTrait;

protected $table      = 'accesslevel_mst';
protected $primaryKey = 'id';
protected $returnType = 'object';

protected $useTimestamps  = true;
protected $useSoftDeletes = true;
protected $skipValidation = true;

protected $allowedFields = ['access_name'];

protected $afterInsert = ['auditInsert'];
protected $afterUpdate = ['auditUpdate'];
protected $afterDelete = ['auditDelete'];

public function SelectAll()
{
    $sql = "SELECT * FROM accesslevel_mst where id <> 1";
    $data = [];
    $result = $this->db->query($sql);
    if ($result->getNumRows() > 0) {
        foreach ($result->getResult() as $row) {
            $data[] = $row;
        }
        return $data;
    }
    return $data;
}

public function InsertData($data){
    $sql = "INSERT INTO accesslevel_mst(access_name) VALUES(?)";
    $value = [$data['access_name']];

    $this->db->query($sql,$value);

    if ($this->db->affectedRows() == '1')
    {
        //$query = $this->db->getLastQuery();
        return TRUE;
    }
        return FALSE;
}

public function delByID($id)
{
    $sql="DELETE FROM accesslevel_mst WHERE id = '".$id."'";
    if ($this->db->query($sql))
    {
        return TRUE;
    }
        return FALSE;

}

}`

But after I try to insert or delete data, nothing has been inserted in the audits table. Im running it in development Environment.

MGatner commented 2 years ago

You need to be using the native Model methods (insert(), update(), etc). If you need to use your custom versions then be sure to trigger the model events (see BaseModel.php in the framework).