2014-05-09 3 views
0

나는이 내 회사/index.ctp에 다음 코드 :CakePHP의 표시 데이터

<div class="companies index"> 
    <h2><?php echo __('Company Details'); ?></h2> 
    <table cellpadding="0" cellspacing="0"> 
    <tr> 
      <th><?php echo $this->Paginator->sort('Id'); ?></th> 
      <th><?php echo $this->Paginator->sort('Company Name'); ?></th> 
      <th><?php echo $this->Paginator->sort('ABN'); ?></th> 
      <th><?php echo "Billing Address"; ?> 
      <?php echo $this->Paginator->sort(''); ?> 
      <?php echo $this->Paginator->sort(''); ?> 
      <?php echo $this->Paginator->sort(''); ?> 
      <?php echo $this->Paginator->sort(''); ?></th> 
      <th><?php echo "Shipping Address"; ?> 
      <?php echo $this->Paginator->sort(''); ?> 
      <?php echo $this->Paginator->sort(''); ?> 
      <?php echo $this->Paginator->sort(''); ?> 
      <?php echo $this->Paginator->sort(''); ?></th> 
      <th><?php echo $this->Paginator->sort('Phone'); ?></th> 
      <th><?php echo $this->Paginator->sort('Email'); ?></th> 
      <th><?php echo $this->Paginator->sort('Fax'); ?></th> 
      <th><?php echo $this->Paginator->sort('Website'); ?></th> 
      <th><?php echo $this->Paginator->sort('Description'); ?></th> 
      <th><?php echo $this->Paginator->sort('License Number'); ?></th> 
      <th class="actions"><?php echo __(''); ?></th> 
    </tr> 
    <?php foreach ($companies as $company): ?> 

    <tr> 
     <td><?php echo h($company['Company']['id']); ?>&nbsp;</td> 
     <td><?php echo h($company['Company']['company_name']); ?>&nbsp;</td> 
     <td><?php echo h($company['Company']['ABN']); ?>&nbsp;</td> 
     <td><?php echo h($company['CompaniesBillingAddress']['company_street_address']); ?>&nbsp; 
     <?php echo h($company['CompaniesBillingAddress']['company_suburb']); ?>&nbsp; 
     <?php echo h($company['CompaniesBillingAddress']['company_state']); ?>&nbsp; 
     <?php echo h($company['CompaniesBillingAddress']['company_postcode']); ?>&nbsp;</td> 
     <td><?php echo h($company['Company']['company_street_address']); ?>&nbsp; 
     <?php echo h($company['Company']['company_suburb']); ?>&nbsp; 
     <?php echo h($company['Company']['company_state']); ?>&nbsp; 
     <?php echo h($company['Company']['company_postcode']); ?>&nbsp;</td> 
     <td><?php echo h($company['Company']['company_phone']); ?>&nbsp;</td> 
     <td><?php echo h($company['Company']['company_email']); ?>&nbsp;</td> 
     <td><?php echo h($company['Company']['company_fax']); ?>&nbsp;</td> 
     <td><?php echo h($company['Company']['company_website']); ?>&nbsp;</td> 
     <td><?php echo h($company['Company']['company_description']); ?>&nbsp;</td> 
     <td><?php echo h($company['Company']['license_number']); ?>&nbsp;</td> 
     <td class="actions"> 

      <?php echo $this->Html->link(__('View'), array('action' => 'view', $company['Company']['id'])); ?> 
      </td> 
    </tr> 
<?php endforeach; ?> 
    </table> 

companiesController :

공공 $ 구성 요소 = 배열 ​​('매기기') ;

public function index() { 
    $this->Company->recursive = 0; 
    $this->set('companies', $this->Paginator->paginate()); 
} 

// 일부 코드 은}

companiesBillingAddressController

public $components = array('Paginator'); 

    public function index() { 
     $this->CompaniesBillingAddress->recursive = 0; 
     $this->set('companiesBillingAddresses', $this->Paginator->paginate()); 
    }} 

CompaniesBillingAddress 테이블은 회사 테이블에 속한다. 회사 BillingAddress 테이블의 데이터를 회사/index.ctp에 표시하려고합니다. "정의되지 않은 색인 : CompaniesBillingAddress [APP \보기 \ 회사 \ 색인 .ctp, 36 행"이라는 오류가 계속 나타납니다. 누군가 나를 기쁘게 도와 줄 수 있습니까?

+0

수용 할 수있는 동작을 추가 했습니까 ?? –

답변

0
$this->Company->recursive = 1; 

귀하의 회사 담당자가 작업을 수행해야합니다. "정의되지 않은 인덱스"와 같은 경우에는 뷰에서 배열을 디버깅하는 것이 좋습니다. 예상 데이터를 찾지 못하면 컨트롤러를 살펴보십시오. 이 경우 오류는 사용자가 사용할 수없는 재귀입니다.

게다가 재귀를 사용하지 말고 containable behaviour을 사용하는 것이 좋습니다. 그래서 재귀를 0으로 설정하면 실제로 좋은 방법입니다.

+0

회사를 $ this-> Company-> recursive = 1로 변경하십시오. 문제를 해결하지 못했습니다. 나는 여전히 같은 오류를 얻는다. 내가 바꿀 필요가있는 것이 있습니까? 그리고 만약 내가 포함 할 수있는 행동을 사용하고 재귀 = 0을 만든 다음 코드에 추가해야 할 것은 무엇입니까? – user3579801