2016-04-14 6 views
0

私のコードに問題があります:ContextErrorException:通知:未定義の変数:tpId in /tmxpage/apache/htdocsEDI/Editracker/src/Matrix/MatrixEdiBundle/Controller/MatrixController.php 435行目、symfonyとIの新しいなぜか分からない。ここContextErrorException:通知:未定義の変数ですか?

はMatrixController.phpのための私のコードです:

public function checkDocumentAction($docType, $direction, $senderId, $receiverId) { 
    $response = 0; 
    $em =$this->getDoctrine()->getManager(); 
    $temp = $em 
     ->getRepository('MatrixEdiBundle:EdiInterchangeId') 
     ->findInterchangeId($senderId); 
    $countTemp = count($temp); 
    if($temp != null) { 
     if($countTemp == 1) { 
     foreach($temp as $key) { 
      $tpId = $key->getEdiTradingPartner(); 
     } 
     } else { 
     $temp1 = $em 
      ->getRepository('MatrixEdiBundle:EdiInterchangeId') 
      ->findInterchangeId($receiverId); 
     $countTemp1 = count($temp1); 
     if($temp1 != null) { 
      if($countTemp1 == 1) { 
      foreach($temp1 as $key) { 
       $tpId = $key->getEdiTradingPartner(); 
      } 
      } elseif($countTemp1 > 1) { 
      foreach($temp1 as $key) { 
       $temp2 = $key->getEdiTradingPartner(); 
       $temp3 = $em 
        ->getRepository('MatrixEdiBundle:EdiInterchangeId') 
        ->findTradingPartner($temp2, $senderId); 
       $countTemp3 = count($temp3); 
       if($countTemp3 == 1) { 
       foreach($temp3 as $key) { 
        $tpId = $key->getEdiTradingPartner(); 
       } 
       } 
      } 
      } 
     } 
     } 

     if ($tpId != null) { 
     $result = $em 
      ->getRepository('MatrixEdiBundle:EdiTradingPartnerTransactions') 
      ->getTpTrans($tpId, $docType, $direction); 
     // if ($result != null) { 
     // $response = 1; 
     // } 
     if ($result != null) { 
      foreach ($result as $key) { 
      $isRequired = $key->getIsRequired(); 
      if ($isRequired == 1) { 
       $response = 1; 
      } else { 
       $response = 2; 
      } 
      } 
     } 
     } 
    } 

    return new Response($response); 
} 

それはここで

matrixcontroller.php内部関数のTPIDがあるrejectedTrans.html.twigのための私の抜粋ですテンプレートのレンダリング中に例外がスローされました( "Notice:未定義変数:tpId、:

{% if transaction != null %} 
    {% for trans in transaction %} 
     <tr> 
     <td style="width: 8%;"> 
      {{ render(controller('MatrixEdiBundle:Matrix:getTradingPartnerName', { 
       'timexID' : trans.ediTransaction.receiverId, 
       'customerID' : trans.ediTransaction.senderId 
      })) }} 
     </td> 
     {% set result=render(controller('MatrixEdiBundle:Matrix:getFile', { 
      'fileName' : trans.ediTransaction.fileName, 
      'senderId': trans.ediTransaction.senderId , 
      'receiverId' : trans.ediTransaction.receiverId, 
      'gsNumber' : trans.ediTransaction 
     }))|split('+', 4) %} 
+0

あなたは$ TPIDが設定されているとき、それは唯一のこれまでのアレイのforeach文での最後の値に設定されることを実現していますか?また、非常に悪い練習であるループ内でクエリを実行している場合、ループ内でクエリしているデータにクエリが正しく記述されていれば、これらのループを削除できます。 – LMS94

答えて

0

$ tpIdは条件でのみ初期化されます。したがって、すべての条件がfalseの場合、変数は定義されません。

がヌルでそれを初期化し

public function checkDocumentAction($docType, $direction, $senderId, $receiverId) { 
    $response = 0; 
    $tpId = null; 

... 
+0

それは解決された答えをありがとう。 – geekInThePink

関連する問題