如何在cakephp3中的表中添加$ _schema数组?架构如下:
public $_schema = array(
'id' => array(
'type' => 'int',
'length' => 11
),
'uuid' => array(
'type' => 'string',
'length' => 40
),
'name' => array(
'type' => 'string',
'length' => 255
)
);
答案 0 :(得分:0)
您可以在表格中的intitialize方法中设置架构,如下所示:
//src/Model/Table/ContactsTable.php
use Cake\Database\Schema\Table as SchemaTable;
public function initialize(array $config){
$table = new SchemaTable(null);
$table
->addColumn('id', [
'type' => 'integer',
'length' => 11,
'null' => false
])
->addColumn('uuid', [
'type' => 'string',
'length' => 255,
'null' => false
])
->addColumn('name', [
'type' => 'string',
'length' => 255,
'null' => false
]);
$this->schema($table);
}
下找到答案