Yii hasAttribute和自定义字段

cwtwac6a  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(210)

如何将hasAttribute与自定义域一起使用?
编码:

if ($model->hasAttribute($attribute)) {
    ...
} else {
    $this->_sendResponse(400, 'Parameter \''.$attribute.'\' is not supported.');
}

实施例
Model.php

class Model extends CActiveRecord
{

public $customField;
...

编码:

$model = new Model;
$model->hasAttribute('customField'); // Returns False.
pbpqsu0x

pbpqsu0x1#

您只需用途:

if (property_exists('Model', $attribute)) {

https://www.php.net/manual/en/function.property-exists.php
hasAttribute将只检查db属性。

相关问题