php - 在 codeigniter4 的模型中使用 $dateFormat INT
问题描述
阅读 CodeIgniter4 (Models) 的文档,我发现了这个。
我尝试使用日期类型为 int 的时间戳,但这不起作用,因为在更新列“updated_at”时它为 0。我的模型是:
<?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';
}
?>
eCrisisModel 是 Model 类的抽象类扩展:
<?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(){
//...
}
}
?>
执行它的控制器是:
<?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);
}
}
?>
哪个是我的错误?为什么系统不记录更新时间戳?
解决方案
推荐阅读
- java - 您如何使用 Junit 和 Eclipse 测试这些 setter 方法?
- java - 方法 A 中的 Junit Mocking/Stubbing 方法 B(非参数化方法 A)
- javascript - 嵌套开关盒
- angular - 量角器结果不一致 - 失败:脚本超时:未收到结果
- amazon-s3 - CloudFormation S3 NotificationConfiguration 到 SQS
- c# - Visual Studio - 运行 Webpack 时出现 Newtonsoft.Json 错误
- javascript - 使用服务器发送的事件访问函数外的范围
- windows - 在 Windows 环境中,如何通过管道将数据卷曲以获取 URL
- java - 面向开发人员的 Hybris 培训材料
- r - RStudio git 存储库消失了