|
public function fields() { return [ // Nome do campo é igual ao nome do atributo 'id', // nome do campo é "email", o nome do atributo correspondente é "email_address" 'email' => 'email_address', // nome do campo é "name", seu valor é definido por um PHP callback 'name' => function ($model) { return $model->first_name . ' ' . $model->last_name; }, ]; } // filtrar alguns campos, melhor usado quando você deseja herdar a implementação do pai // e deseja esconder alguns campos confidenciais.
|
|
// explicitly list every field, best used when you want to make sure the changes // in your DB table or model attributes do not cause your field changes (to keep API backward compatibility). public function fields() { return [ // field name is the same as the attribute name 'id', // field name is "email", the corresponding attribute name is "email_address" 'email' => 'email_address', // field name is "name", its value is defined by a PHP callback 'name' => function ($model) { return $model->first_name . ' ' . $model->last_name; }, ]; } // filter out some fields, best used when you want to inherit the parent implementation // and blacklist some sensitive fields. public function fields() { $fields = parent::fields(); // remove fields that contain sensitive information unset($fields['auth_key'], $fields['password_hash'], $fields['password_reset_token']); return $fields; }
|