Reading the documentation of CodeIgniter4 (Models), i found this.
I tried use a timestamps with a type date of int, but this not working because at updated the column "updated_at" it is 0. My model is:
PHP Code:
<?php namespace App\Models;
use CodeIgniter\Model;
class UserModel extends eCrisisModel{
protected $table = 'user';
protected $primaryKey = 'id';
protected $returnType = 'array';
protected $useSoftDeletes = true;
protected $allowedFields = ["login", "pass", "about_me", "utc"];
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
protected $dateFormat = 'int';
}
?>
The eCrisisModel is a abstract class extends of Model class:
PHP Code:
<?php namespace App\Models;
use CodeIgniter\Model;
// existentialCrisis
abstract class eCrisisModel extends Model{
protected $prefix = '';
protected $exists = false;
protected $builder;
public function __construct(...$params){
parent::__construct(...$params);
//"I am therefore I think"
if(!$this->db->tableExists($this->prefix.$this->table)){
$this->creatingMe();
$this->exists = true;
}
$this->builder = $this->db->table($this->table);
}
public function creatingMe(){
//...
}
}
?>
The controller where it is executed is:
PHP Code:
<?php namespace App\Controllers;
use CodeIgniter\Controller;
class Test extends Controller{
public function __construct(){
$this->UserModel = model('App\Models\UserModel');
$this->SettingModel = model('App\Models\SettingModel');
}
public function index(){
$data = [
'login' => 'jiji',
'pass' => password_hash("passss",PASSWORD_DEFAULT),
'about_me' => 'xd',
'utc' => -2.75
];
$this->UserModel->builder->where('id', 1);
$this->UserModel->builder->update($data);
}
}
?>
And the database after of the update is:
Which is my error ? why the system not recording the update timestamp?
(The link of this problem in StackOverflow is:
https://stackoverflow.com/questions/6462...4_64624957)