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 ?