php - Yii2: Model 'fields' ignore null values -
yii 2 docs explains can set fields should returned default toarray()
. (http://www.yiiframework.com/doc-2.0/yii-base-model.html#fields()-detail)
theres possibility ignore when contains null values?
function fields() { return [ 'email', // ignore if email null. 'fullname', // ignore if fullname null. ]; }
try this:
function field() { $return = []; if(!empty($this->email)) { $return[] = 'email'; } if(!empty($this->fullname)) { $return[] = 'fullname'; } return $return; }
Comments
Post a Comment