我假设您已经设置了模型。
在您的控制器中,您需要将变量分配给find(list) 调用的结果,然后将它们分配给set()。这是一个项目的示例,其中我有请求、货币等的下拉列表:
$requests = $this->Purchase->Request->find('list');
$currencies = $this->Purchase->Currency->find('list', $options);
$shippingCurrencies = $this->Purchase->ShippingCurrency->find('list', $options);
$finalCurrencies = $this->Purchase->FinalCurrency->find('list', $options);
$receivers = $this->Purchase->ReceiverUser->find('list');
$this->set(compact('requests', 'currencies', 'shippingCurrencies', 'finalCurrencies', 'receivers'));
(您也可以通过一系列$this->set(...) 调用而不是使用变量和$this->set(compact(...)) 来做到这一点。)
然后在您看来,您使用Form->input() 调用来进行选择语句。这是另一个例子:
$empty_currency = array('empty'=>'(choose a currency)');
...
echo "<table class=\"all order\"><tr><td>\n";
echo $this->Form->input('tax_currency_id', $empty_currency);
echo "</td></tr></table>\n";
echo "<table><tr><td colspan='2' class='all order receive'>\n";
echo $this->Form->input('shipping_comment');
echo "</td></tr><tr class='all order costing'><td>\n";
echo $this->Form->input('shipping_cost');
echo "</td><td>\n";
echo $this->Form->input('shipping_currency_id', $empty_currency);
echo "</td></tr></table>\n";
有时,如果您没有完全遵循命名约定,那么您必须在输入调用中指定 array(...'type'=>'select')。这是一个例子:
echo $this->Form->input('budget_year_dflt', array('type'=>'select', 'options'=>$budgetYears, 'label'=>'Default Budget Year'));
如果您是 cakephp 新手,请帮自己一个忙,在进行表格设计和开始开发之前彻底阅读并理解命名约定。如果你遵循他们的约定,生活会很容易,如果你不遵守,生活会很艰难......