'guard' => false in newEntity() options not working in Cakephp4

There’s certainly something that I do wrong, but I can’t use correctly the guard option of newEntity() method.

// Entity
class Bloc extends AbstractBloc
{
    protected $_accessible = [
    	'*' => false // All fields are protected against mass assignment
    ];
}

'guard' => false doesn’t allow to save my entity in this example :

// Controller
public function test()
{
	$entity = $this->Blocs->newEntity([
		'titre' => 'TEST ASSIGNEMENT',
		'rubrique_id' => 282,
		'description' => 'Content'
	],	['guard' => false]); // guard is false but the entity is not saved
	if ($this->Blocs->save($entity)) {
		return $this->redirect([...]);
	}
	else {
		die('save is false');
	}
}

Note that there’s no error in $entity and when I set '*' => true in $_accessible then $entity is well saved.

What am I doing wrong ?

You need to use 'accessibleFields' => '*' instead of 'guard' => false.

Ah thank you ADmad, it works !

Anyway, it’s strange,I’ve seen $this->table->newEntity($data, ['validate' => false, 'guard' => false]) in plugin FileStorage 4.0 :

But I never tried it…

Well you need to take that up with the plugin’s author :slightly_smiling_face:.