我的公司/ index.ctp中有以下代码:
<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']); ?> </td>
<td><?php echo h($company['Company']['company_name']); ?> </td>
<td><?php echo h($company['Company']['ABN']); ?> </td>
<td><?php echo h($company['CompaniesBillingAddress']['company_street_address']); ?>
<?php echo h($company['CompaniesBillingAddress']['company_suburb']); ?>
<?php echo h($company['CompaniesBillingAddress']['company_state']); ?>
<?php echo h($company['CompaniesBillingAddress']['company_postcode']); ?> </td>
<td><?php echo h($company['Company']['company_street_address']); ?>
<?php echo h($company['Company']['company_suburb']); ?>
<?php echo h($company['Company']['company_state']); ?>
<?php echo h($company['Company']['company_postcode']); ?> </td>
<td><?php echo h($company['Company']['company_phone']); ?> </td>
<td><?php echo h($company['Company']['company_email']); ?> </td>
<td><?php echo h($company['Company']['company_fax']); ?> </td>
<td><?php echo h($company['Company']['company_website']); ?> </td>
<td><?php echo h($company['Company']['company_description']); ?> </td>
<td><?php echo h($company['Company']['license_number']); ?> </td>
<td class="actions">
<?php echo $this->Html->link(__('View'), array('action' => 'view', $company['Company']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
companiesController:
public $ components = array(&#39; Paginator&#39;);
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表属于Companies表。我希望companiesBillingAddress表中的数据显示在companies / index.ctp中。 我一直收到错误说&#34;未定义的索引:CompaniesBillingAddress [APP \ View \ Companies \ index.ctp,第36行&#34;。有人能帮帮我吗?
答案 0 :(得分:0)
$this->Company->recursive = 1;
在你的公司控制器应该做的工作。在诸如&#34; Undefined index&#34;是在视图中调试您的数组。如果您找不到所需的数据,请查看您的控制器。在这种情况下,错误是您的禁用递归。
此外,我不建议使用递归而是containable behaviour。 因此,将递归设置为0实际上是一种好方法。