Доброе время суток, товарищи!
Столкнулся с задачей, которую сам решить не смог.
Задача:
Нужно массив images[] запихнуть в поле с типом данных json array, в принципе сеттер легко справился с полями типа текст:
<input type="text" name="images[image_intro_alt]" >
Но вот как запихнуть в
images[image_intro] с типом
file значение, которое я получаю из метода
$this->uploadImage();
Есть поля:
<input type="text" name="images[image_intro_alt]" >
<input type="text" name="images[image_intro_caption]">
<!-- бла бла бла -->
<input type="file" name="images[image_intro]">
Так я заполняю массив.
Entity->setImages($request->request->get('images'))
/**
* upload image content
* @param $request
* @return bool|string
*/
public function uploadImage($request){
$destinationPath = '/web/uploads/content';
$file = $request;
$contentFullTextImageDir = $this->container->getParameter('kernel.root_dir') . '/../'.$destinationPath;
if (null !== $file) {
$fileName = $file->getClientOriginalName();
$file->move($contentFullTextImageDir, $fileName);
return $destinationPath.'/'.$fileName; //путь к файлу и его имя
}
return false;
}
Огромное спасибо за внимание!