2012-08-15 5 views
-1

내가 $senderName['Account']['company_name']와 라인에 undefined index error: Account 무엇입니까 뷰를 작성하지만, 여기 CakePHP의 정의되지 않은 인덱스

array(
    (int) 0 => array(
     'Account' => array(
      'id' => '0', 
      'street' => 'SYSTEM', 
      'city' => 'SYSTEM', 
      'postcode' => '0', 
      'state' => 'SYS', 
      'country' => 'SYS', 
      'active' => true, 
      'company_name' => 'SYSTEM', 
      'abn' => '0' 
     ), 
     'Template' => array(), 
     'User' => array(), 
     'Invoice' => array() 
    ), 

를 배열 인쇄 변수를 디버깅 할 때 내보기에 대한 코드 인 경우

<?php foreach($invoice as $invoices):?> 
       <?php foreach($senderName as $senderName):?> 
       <?php foreach($receiverName as $receiverName):?> 
        <tr> 
       <tr> 
         <td align='center'><?php echo $senderName['Account']['company_name']; ?></td> 
         <td align='center'><?php echo $receiverName['Account']['company_name']; ?></td> 
         <td align='center'><?php echo $this->Form->Html->link($invoices['Invoice']['id'], 
            array('controller' => 'Invoices','action'=>'viewinvoice',$invoices['Invoice']['id'])); ?></td> 
        </tr> 
       <?php endforeach; ?> 
       <?php endforeach; ?> 
       <?php endforeach; ?> 

그리고 내 관련된 기능이 여기에 해당 될 경우

 $accounts2=$this->User->find('list', array(
     'fields'=>array('account_id'), 
     'conditions' => array(
     'id' => $this->Auth->user('id')))); 


     $invoices=$this->Invoice->find('all', array(
     'conditions' => array(
     'Invoice.receiver_id' => $accounts2))); 

     $sender=$this->Invoice->Find('list', array('fields'=>('sender_id'))); 
     $receiver=$this->Invoice->Find('list', array('fields'=>('receiver_id'))); 

     $senderName=$this->Account->Find('all', array(
     'conditions' => array(
     'id'=>array_values($sender)))); 

     $receiverName=$this->Account->find('all', array(
     'conditions' => array(
     'id'=>array_values($receiver)))); 
debug($senderName); 

     $this->set('senderName', $senderName); 
     $this->set('accounts2', $accounts2); 
     $this->set('receiverName', $receiverName); 
     $this->set('sender',$sender); 
     $this->set('receiver',$receiver); 
     $this->set('invoice', $invoices); 

} 

답변

1

나는 당신이보기에서 코드를 검토한다고 생각합니다.

3

컴퓨터가 ri ght. :)

$senderName['Account']['company_name'] 

존재하지 않습니다.

$senderName['0']['Account']['company_name'] 

않습니다.

데이터는 senderName에 여러 계정이있어이 형식으로 제공됩니다.

편집 :

모델에서도 관계를 제공 할 수 있습니까? foreach는 array_expression에서 가치 변수에

<?php foreach($senderName as $senderName):?> 
<?php foreach($receiverName as $receiverName):?> 

이 달라야하지만 당신은 같은 변수 이름을 사용, 이것에 대한 다른 이름을 사용하시기 바랍니다있다 :