我的代码出现了问题:ContextErrorException:注意:未定义的变量:/ tmxpage/apache/htdocsEDI/Editracker/src/Matrix/MatrixEdiBundle/Controller/MatrixController.php第435行中的tpId,我是symfony的新手,我不知道为什么,。
这是我的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的片段,因为它还说:在呈现模板期间抛出异常("注意:未定义的变量: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 :(得分:0)
$ tpId仅在条件下初始化。因此,如果所有条件都为假,则不会定义变量。
使用null
初始化它public function checkDocumentAction($docType, $direction, $senderId, $receiverId) {
$response = 0;
$tpId = null;
...