trejder
(Tomasz)
1
How can I check type (column type) of model’s attribute in Yii2?
This old answer gave me a conclusion, that in Yii1 I can use something like that:
$model->getMetaData()->columns['attribute-name']->type;
But I was unsuccessful in porting this solution to Yii2. Can someone help?
trejder
(Tomasz)
2
You can use:
$model->getTableSchema()->getColumn('attr')
or:
$model->getTableSchema()->columns['attr']
and then read dbType, phpType or type, according to what… type of type you’re looking for.
For example:
$model->getTableSchema()->columns['attr']->type
Founded this myself in exactly the same time as cetver does! :>