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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -