【发布时间】:2018-03-22 15:46:51
【问题描述】:
我有三张桌子:
BudgetRevenues - 属于AnnualOperatingBudgets
AnnualOperatingBudgets 有一个 Azinstitutions
在我的预算收入添加表单中,第一个选择是预算年度和机构。
public function add()
{
$budgetRevenue = $this->BudgetRevenues->newEntity();
$associated = [ 'RevenueTitles', 'AnnualOperatingBudgets', 'AnnualOperatingBudgets.Azinstitutions'];
if ($this->request->is('post')) {
$budgetRevenue = $this->BudgetRevenues->patchEntity($budgetRevenue, $this->request->getData(), ['associated' => $associated]);
if ($this->BudgetRevenues->save($budgetRevenue)) {
$this->Flash->success(__('The budget revenue has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The budget revenue could not be saved. Please, try again.'));
}
$annualOperatingBudgets = $this->BudgetRevenues->AnnualOperatingBudgets->find('list', ['keyField' => 'id', 'valueField' => ['budget_year', 'azinstitutions_id']]);
$revenueTitles = $this->BudgetRevenues->RevenueTitles->find('list', ['keyField' => 'id', 'valueField' => 'revenue_title']);
$this->set(compact('budgetRevenue', 'revenueTitles', 'annualOperatingBudgets', 'AnnualOperatingBudgets.Azinstitutions'));
}
在我的代码中,我可以调用预算年度(AnnualOperatingBudgets 中的一个字段)和 azinstitution_id。但我希望它显示机构的名称。这是在由 AnnualOperatingBudgets 表中的 azinstitution_id 链接的 azinstitutions 表中。
现在表格显示 2015;1 我希望它显示 2015 ASU
我的 add.ctp 看起来像这样:
<div class="budgetRevenues form large-9 medium-8 columns content">
<?= $this->Form->create($budgetRevenue) ?>
<fieldset>
<legend><?= __('Add Budget Revenue') ?></legend>
<?php
echo $this->Form->control('annual_operating_budget_id', ['label' => 'Budget Year & Institution'], ['options' => $annualOperatingBudgets ]);
echo $this->Form->control('revenue');
echo $this->Form->control('revenue_title_id', ['options' => $revenueTitles]);
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
【问题讨论】:
标签: cakephp cakephp-3.x