【问题标题】:How to add a schema to a table in cakephp3如何在 cakephp3 中向表中添加模式
【发布时间】:2015-07-05 11:03:32
【问题描述】:

如何将 $_schema 数组添加到 cakephp3 的表中?架构如下所示:

public $_schema = array(

    'id' => array(
        'type' => 'int',
        'length' => 11
    ),
    'uuid' => array(
        'type' => 'string',
        'length' => 40
    ),
    'name' => array(
        'type' => 'string',
        'length' => 255
    )

);

【问题讨论】:

    标签: cakephp model cakephp-3.0 information-schema


    【解决方案1】:

    您可以像这样在表的 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);
    }
    

    答案可以在https://github.com/cakephp/cakephp/issues/5251下找到

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-02
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2021-06-29
      相关资源
      最近更新 更多