gpt4 book ai didi

php - 上下文错误异常 : Notice: Undefined variable?

转载 作者:行者123 更新时间:2023-11-29 21:08:33 26 4
gpt4 key购买 nike

我的代码有问题,它说:ContextErrorException:注意: undefined variable :tpId in/tmxpage/apache/htdocsEDI/Editracker/src/Matrix/MatrixEdiBundle/Controller/MatrixController.php line 435,我是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);
}

it's a function inside the matrixcontroller.php

这是我的rejectedTrans.html.twig片段,其中呈现了tpId,因为它还显示:在呈现模板期间抛出异常(“注意: 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) %}

最佳答案

$tpId 仅在条件下初始化。因此,如果所有条件均为 false,则不会定义变量。

初始化为null

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

...

关于php - 上下文错误异常 : Notice: Undefined variable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36613667/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com