How can I check type (column type) of model's attribute in Yii2?
This old Yii Forum 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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.