2017-09-04 8 views
1

私は実体上のファイルをアップロードしようが、私はメンバ関数guessExtensionに実際にsymfonyの呼び出し()

コール()配列

上の問題が来るを取得私のコントローラの次の行から:

$ fileName = md5( 'uniqid())。'。$ file-> guessExtension();

なぜこのエラーが発生しているのですか?誰かが私に問題を解決するのを助けてくれることを願ってここではどうもありがとう事前に

敬具

私のエンティティ:

class Gig 
{ 

    private $flyer; 

public function setFlyer($flyer) 
    { 
     $this->flyer = $flyer; 

     return $this; 
    } 


    public function getFlyer() 
    { 
     return $this->flyer; 
    } 

... 

ここに私のコントローラ:ここ

public function addGigAction(Request $request , $id){ 

     $em = $this->getDoctrine()->getManager(); 

     $artist = $em->getRepository('BookingRoosterBundle:artist')->find($id); 

     if (null === $artist) { 
      throw new NotFoundHttpException("L'annonce d'id ".$id." n'existe pas."); 
     } 

     $gig = new Gig(); 
     //on inject l'artist directement 
     $gig->setArtist($artist); 

     $form = $this->createForm(GigType::class, $gig); 


     if ($request->isMethod('POST') && $form->handleRequest($request)->isValid()) { 

      $file = $gig->getFlyer(); 

      $fileName = md5(uniqid()).'.'.$file->guessExtension(); 

      $file->move(
       $this->getParameter('upload_directory'), 
       $fileName 
      ); 

      $gig->setFlyer($fileName); 

      $em->persist($gig); 
      $em->flush(); 

      $request->getSession()->getFlashBag()->add('notice', 'Date bien ajouté pour l\'artiste'); 

      return $this->redirectToRoute('booking_rooster_view', array(
       'id' => $artist->getId() 
      )); 
     } 

     return $this->render('BookingRoosterBundle:Artist:addGig.html.twig' , array(
      'artist' => $artist, 
      'form' => $form->createView(), 
     )); 

    } 

$ファイルからの私のダンプ:

array(1) { ["file"]=> object(Symfony\Component\HttpFoundation\File\UploadedFile)#37 (7) { ["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> bool(false) ["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(38) "techno_flyer_by_curtismack-d4lbtu5.png" ["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(9) "image/png" ["size":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(243010) ["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(0) ["pathName":"SplFileInfo":private]=> string(45) "/Applications/XAMPP/xamppfiles/temp/phpdfJ98s" ["fileName":"SplFileInfo":private]=> string(9) "phpdfJ98s" } } 
+0

:あなたはgetFlyer()で得た値を設定するが、あなたがここに配列を持っていると思われない場所がわからない、単にこのような何かを行います'? $ファイルをダンプしましたか? –

+0

はい私はダンプをしました!私はダンプ結果 –

答えて

2

だから私はまだやるあなたの `$ gig-> getFlyerを(COMMEんwher)

$fileArray = $gig->getFlyer(); 
$file = $fileArray['file']; 
$fileName = md5(uniqid()).'.'.$file->guessExtension(); 
+0

作業人とのポストの更新を行います!どうもありがとう !!!! –

+0

偉大な、解決されたように答えを置くことを忘れないでください –

+0

完了した男:)ありがとうもう一度 –

関連する問題