部落格
當紅俱樂部
登入
Ci4 Model 產生器
mysql 指令產生 ci4 相關檔案
推薦使用 PHP 資料庫管理工具
另外一個線上產生器
SQL 指令
CREATE TABLE `activity_logs` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` text NOT NULL, `user` text NOT NULL, `ip_address` text NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
請替換為需要的 sql 指令
Models
<?php namespace App\Models; use CodeIgniter\Model; class BaseModel extends Model { protected $table = ''; protected $primaryKey = ''; protected $useAutoIncrement = true; protected $useSoftDeletes = false; protected $allowedFields = [""]; protected $useTimestamps = true; protected $dateFormat = 'datetime'; protected $createdField = ''; protected $updatedField = ''; // protected $deletedField = ''; // Validation protected $validationRules = []; protected $validationMessages = []; protected $skipValidation = false; protected $cleanValidationRules = true; protected $returnType = \App\Entities\TableEntity::class; public function getTable() { return $this->table; } # ref: https://codeigniter4.github.io/userguide/models/model.html?highlight=model%20get%20builder#working-with-query-builder }
Entities
<?php namespace App\Entities; use CodeIgniter\Entity; class TableEntity extends Entity { }
結果
提示