1
我想用ajax調用上傳文件,但是當我去保存我的只保存與anagrafic的關係。 我聲明如果我試圖正常保存正常工作。Symfony2 Ajax上傳
就好像它沒有加載對象UploadFile! 我按照symfony的食譜http://symfony.com/doc/2.1/cookbook/doctrine/file_uploads.html 在我的控制器創建的表
public function fileCreateAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('MyBusinessBundle:Anagrafic')->find($id);
$media = new Multimedia();
$form = $this->createForm(new MultimediaType(), $media);
if ($this->getRequest()->isMethod('POST')) {
$form->bind($this->getRequest());
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$media->setAnagrafic($entity);
$em->persist($media);
$em->flush();
$response = new Response();
$output = array('success' => true);
$response->headers->set('Content-Type', 'application/json');
$response->setContent(json_encode($output));
}
}
我試圖做的var_dump的後續代碼var_dump($媒體);並返回:
object(My\BusinessBundle\Entity\Multimedia)[337]
private 'id' => null
private 'percorso' => null
private 'alt' => null
private 'type' => null
public 'file' => null
private 'anagrafic' => null