Answer the question
In order to leave comments, you need to log in
How can I set a script or define a page action in fields() (REST) (Yii2)?
I need to somehow display different fields for different Actions (REST)
// 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
'user_id','name', 'email','gender','age','image'
];
}
Answer the question
In order to leave comments, you need to log in
You can try like this:
$action = Yii::$app->requestedAction;
if ($action->id === 'form' && $action->controller->id === 'default') {
return [...];
} else {
return [...];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question