0
我有一個圖片上傳,只注意到的是兩件事情:圖片沒有顯示提交後並在刷新的形式重新提交,Symfony2的
1)形式重新提交上刷新。顯然不希望那樣。我找到了一個平坦的PHP答案。我想知道做什麼symfony的方式。
2)我上傳我必須刷新看到圖像文件後,這就是我如何發現問題1.
控制器代碼:
public function displayThreadAction($thread_Id)
{
$em = $this->getDoctrine()->getManager();
$thread = $em->getRepository('GreenMonkeyDevGlassShopBundle:ForumThread')->find($thread_Id);
$post = new ForumReply();
$post->setThreadId($thread);
$form = $this->createForm(new ReplyImageForm(), $post);
$request = $this->getRequest();
if ($request->isMethod('POST')){
$form->bind($request);
if ($form->isValid()){
$image = new ForumReplyImage();
$image->setImageName($form['imageName']->getData());
$image->setImageFile($form['imageFile']->getData());
$image->upload();
$image->setReplyId($post);
$em->persist($post);
$em->persist($image);
$em->flush();
$post = new ForumReply();
$post->setThreadId($thread);
$form = $this->createForm(new ReplyImageForm(), $post);
}
}
return $this->render('GreenMonkeyDevGlassShopBundle:Forum:forum_thread.html.twig', array('thread' => $thread, 'form' => $form->createView()));