Yii2:如何获取模型属性的数据库属性?

时间:2016-07-15 16:54:18

标签: model-view-controller yii attributes yii2 schema

如何获取模型属性的数据库列属性?与数据类型,默认值,大小等相似。

1 个答案:

答案 0 :(得分:0)

您可以使用$customer_model->getTableSchema()Customer::getTableSchema()

为您提供以下内容:

yii\db\TableSchema#1 (
    [schemaName] => null
    [name] => 'customers'
    [fullName] => 'customers'
    [primaryKey] => [
        0 => 'customerID'
    ]
    [sequenceName] => ''
    [foreignKeys] => [
        0 => [
            0 => 'orders'
            'ord_customerID' => 'customerID'
        ]
    ]
    [columns] => [
        'customerID' => yii\db\ColumnSchema#2 (
            [name] => 'customerID'
            [allowNull] => false
            [type] => 'integer'
            [phpType] => 'integer'
            [dbType] => 'int(10) unsigned'
            [defaultValue] => null
            [enumValues] => null
            [size] => 10
            [precision] => 10
            [scale] => null
            [isPrimaryKey] => true
            [autoIncrement] => true
            [unsigned] => true
            [comment] => ''
        )
    ...