I have a field type
image_cover on my database. I have a field type
file on my form:
<?php echo $this->Form->create($event, ['type' => 'file']) echo $this->Form->file('image_cover') echo $this->Form->submit('Send') echo $this->Form->end() ?>
$this->request->data('image_cover') is an array with file name, size etc.
I need the value of the
image_cover change to only the name of the file.
I'm trying do this on
beforeSave but is not working
There are a few ways of doing this, but the easiest to understand is to have an input field that is not part of the schema of your table. For example, instead of
image_cover you could have
Make sure you set
image_file in the
$_accessible list of fields of your entity. You will be able to access this field in
beforeSave so you can store it.
There is this plugin that will do exactly that for you: https://github.com/davidyell/CakePHP3-Proffer