2014-05-09 51 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表屬於公司表。我希望companiesBillingAddress表中的數據顯示在companies/index.ctp中。 我不斷收到一條錯誤消息:「未定義索引:CompaniesBillingAddress [APP \ View \ Companies \ index.ctp,第36行」。有人能幫助我嗎?

+0

是否附加了可容納的行爲? –

回答

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

在您的公司控制器應該做的工作。像「未定義索引」這樣的情況下,最好的方法是在視圖中調試你的數組。如果您沒有找到您期望的數據,請查看您的控制器。在這種情況下,故障是您禁用的遞歸。我不推薦使用遞歸,而是使用containable behaviour。 因此將遞歸設置爲0實際上是一種好方法。

+0

將公司控制器更改爲$ this-> Company-> recursive = 1;沒有解決問題。我仍然有同樣的錯誤。還有什麼我需要改變?如果我使用可容忍的行爲並使遞歸= 0,那麼我應該在代碼中添加什麼? – user3579801