对象的方法不存在?

时间:2016-04-26 02:55:04

标签: php sql symfony twig entity

我是symfony2的新手我正在尝试创建搜索功能并获得此功能

  

错误'方法'ediTransaction“for object”Matrix \ MatrixEdiBundle \ Entity \ Edi997SegmentInError“在MatrixEdiBundle中不存在:Matrix:rejectedTrans.html.twig at 58'

它是什么问题?任何人吗?

存储库

class Edi997DetailsRepository extends EntityRepository{
    public function getDetails($gsNumber, $senderId, $receiverId, $page = 1, $limit = 5 ){

    $em = $this->getEntityManager();

    $query = $em->createQuery(

        'SELECT  partial a.{id, ak301, ak401},
         partial b.{errorCode, condition},
         partial c.{edi997DetailId, errorCodeId, noOfTrans},
         partial d.{ediTransactionId, senderId, receiverId, gsNumber, isaNumber, fileName}
        FROM MatrixEdiBundle:Edi997SegmentInError a
        JOIN a.ediAk403ErrorCodes b
        JOIN a.edi997Details c
        JOIN c.ediTransaction d
        WHERE d.gsNumber LIKE :gsNumber
        AND d.senderId LIKE :senderId
        AND d.receiverId LIKE :receiverId
        AND c.errorCodeId != 1
        AND d.flag = 1')
        ->setParameter('gsNumber', "%$gsNumber%")
        ->setParameter('senderId', "%$senderId%")
        ->setParameter('receiverId', "%$receiverId%")
        ->setFirstResult(($page-1)*$limit)
        ->setMaxResults($limit);

        $paginator = new Paginator($query, $fetchJoinCollection = false );

        $paginator->setUseOutputWalkers(false);

    return $paginator;
   }
}

Twig:

{% if transaction != null %}
                        {% for trans in transaction %}
                            <tr>
                                <td style="width: 11%;">
                                  {{ 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.receiverId , 'receiverId' : trans.ediTransaction.senderId }))|split('+', 4)
                                %}

                                <td style="width: 10%;">{{ result[0] }}</td>
                                <td style="width: 40%;">{{ result[3] }}<br><br>
                                    {% if trans.errorCodeId == 2 %}
                                        <span style="background-color: yellow;">Accepted but <br/>errors were <br/>noted</span><br/>
                                    {% elseif trans.errorCodeId == 3 %}
                                        <span style="background-color: yellow;">Partially<br/> Accepted</span><br/><br/>
                                            {{ trans.acceptedTrans }} Accepted,<br/>
                                            {{ trans.noOfTrans - trans.acceptedTrans }} Rejected
                                    {% else %}
                                        <span style="background-color: yellow;">Rejected</span>
                                    {% endif %}
                                    <br/>

                                    {% 
                                        set error=render(controller('MatrixEdiBundle:Matrix:getError', {'id': trans.edi997DetailId }))|split('+') 
                                    %}
                                    <span>
                                        <p style="white-space: normal;">
                                            {% if error[0] != "0" %}
                                                {{ error[0] }}{{ "%02d"|format(error[1]) }}<br/>
                                                {{ error[2] }}
                                            {% else %}
                                                Errors were not specified in 997 file
                                            {% endif %}
                                        </p>
                                    </span>
                                </td>
                                <td style="width: 10%;">{{ result[2] }}</td>
                                <td style="width: 7%;">{{ result[1] }}</td>
                                <td style="width: 5%;">{{ trans.noOfTrans }}</td>
                                <td style="width: 7%;">{{ trans.ediTransaction.receiverId }}</td>
                                <td style="width: 8%;">{{ trans.ediTransaction.senderId }}</td>
                                <td>
                                  <a href="" data-href="{{ path('matrix_edi_deleteFile', { 'id':trans.ediTransaction.ediTransactionId,'filename': trans.ediTransaction.fileName, 'url': 'matrix_edi_rejectedOutboundTrans' }) }}" data-toggle="modal" data-target="#confirm-delete"><center><i class="fa fa-trash o" style="color:#1975A3;"></i></center></a>
                                </td>
                            </tr>
                        {% endfor %}
                    {% else %}
                        <tr>
                            <td colspan="15" class="alignment result"> No Result Found </td>
                        </tr>
                    {% endif %}

1 个答案:

答案 0 :(得分:1)

答案是错误的。

在您的Edi997SegmentInError实体对象中,没有ediTransaction方法。

可能的原因:

  1. 该方法不存在于任何对象中
  2. 该方法存在于     对象,而不是您正在访问的对象
  3. 查看您的存储库方法,该方法似乎位于您的Edi997Details实体中。

    据推测,您可以通过{{trans.edi997Details.ediTransaction.receiverId}}访问它 - 但我真的在猜测 - 您必须在树枝中正确地遵循您的对象层次结构。如果您不确定自己确切要访问哪个对象,请尝试使用{{dump(trans)}}查看您拥有的内容。