dtvnnhh8992 2016-04-14 04:02
浏览 61

ContextErrorException:注意:未定义的变量?

I got a problem with my code it says : ContextErrorException: Notice: Undefined variable: tpId in /tmxpage/apache/htdocsEDI/Editracker/src/Matrix/MatrixEdiBundle/Controller/MatrixController.php line 435 , im new to symfony and I don't know why,.

here is my code for 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);
}

it's a function inside the matrixcontroller.php

Here is my snippet for rejectedTrans.html.twig where the tpId is rendered, coz it also says :An exception has been thrown during the rendering of a template ("Notice: Undefined variable: 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) %}
  • 写回答

1条回答 默认 最新

  • douzi1991 2016-04-14 06:11
    关注

    $tpId initializes only in conditions. So if all conditions is false, variable will not be defined.

    Initialize it with null

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

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)