Looking for help with requirePresence()


#1

Cakephp3.5.
My codes:
In Model/Table/ArticlesTable
public function validationDefault(Validator $validator)
{
$validator
->requirePresence(‘title’,‘update’)
->notEmpty(‘title’,‘Title must be not empty’)
->minLength(‘title’, 10)
->maxLength(‘title’, 255)
->notEmpty(‘body’)
->minLength(‘body’, 10);

    return $validator;
}

In Controller/ArticlesController
$save= array(
‘title’ => ‘title’,
‘body’ => ‘1234567890’
);
$article = $this->Articles->newEntity();
$article = $this->Articles->patchEntity($article, $save);
if ($this->Articles->save($article)) {
$data = [200,‘success msg’];
} else {
$data = [400, $article->errors()];
}
//==============
When I add new data, there have a notice is ‘Title must be not empty’,But my
$validator->requirePresence(‘title’,‘update’) ‘s mode is update,
Why warning it when I add new data?


#2

Are you allowing marshaling in your entity?