Hello,
I want to check the extension of an uploaded file so my form is:
(Don’t worry about FormB which simply use CakePHP Bootstrap plugin)
<?= $this->FormB->create($site, ['horizontal' => true, 'type' => 'file']) ?>
<?= $this->FormB->input('guide.fileCard', ['label' => __("upload your card"), 'type' => 'file']); ?>
<?= $this->FormB->end() ?>
And my GuidesTable.php is:
public function validationDefault(Validator $validator) {
$validator
->allowEmpty('id', 'create')
->add('id', 'valid', ['rule' => 'numeric'])
->add('site_id', 'valid', ['rule' => 'numeric'])
->add('fileCard', 'file', [
'rule' => ['uploadedFile' => ['types' => ['image/png', 'image/jpeg', 'application/pdf']]], // It's what I expect to check
'message' => __("authorized extensions: jpg, png, pdf")
]);
return $validator;
}
Guide.php:
class Guide extends Entity {
protected $_accessible = [
'site_id' => true,
'card' => true,
'fileCard' => true,
];
}
But I get the following error:
`Error: Unable to call method "Array" in "default" provider for field "fileCard"`