yii\validators\RequiredValidator fails when PUT in RESTful

In a RESTful app, in a POST request, with a rule like


 

    public function rules()

    {

        return [

            ['attributeX', 'required'],

        ];

    }



A POST request with body parameteres like


{}

Would throw a "attributeX required" error

But in a PUT request, It would not.

According to documentation.


This validator checks if the input value is provided and not empty.


By default, an input is considered empty if its value is an empty string, an empty array or a null

In the same PUT request with body parameteres like


{}

Wouldn’t $_POST[‘attributeX’]; be null?

validation is done in the model layer, as long as you set the attributes and call validate/save on the model the validation should run, I don’t think that should be problem provided your doing it right