Answer the question
In order to leave comments, you need to log in
How to update/create json values via doctrine in a field with type given json array?
Good day, comrades!
I ran into a problem that I couldn't solve myself.
Task: You need to push the images[] array into a field with the json array data type , in principle, the setter easily coped with text type fields:
<input type="text" name="images[image_intro_alt]" >
$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;
}
Answer the question
In order to leave comments, you need to log in
Do you want to save the url?
The path to web/uploads/content corresponds to what in the query string? By default, upload/content?
Then it should be returned as a webpath, i.e. /uploads/content.
Well, and, accordingly, then something in the spirit
$images = $request->request->get('images');
$images['image_intro'] = $service->uploadImage($request);
$entity->setImages($images);
$em->flush();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question