Get model attribute type in Yii2

How to check the type (column type) of a model attribute in Yii2?

This old Yii Forum answer gave me the conclusion that in Yii1 I can use something like this:

$model->getMetaData()->columns['attribute-name']->type; 

But I could not transfer this solution to Yii2. Can anyone help?

+5
source share
1 answer

You can use:

 $model->getTableSchema()->getColumn('attr') 

or

 $model->getTableSchema()->columns['attr'] 

and then read dbType , phpType or type , according to what ... the type of type you are looking for.

For instance:

 $model->getTableSchema()->columns['attr']->type 
+5
source

All Articles