我确信这很简单,但我无法弄清楚如何实现它:
我的模型包含title
和sub_title
列;频繁的条目具有相同的title
,并且只能由sub_title
区分。所以,我需要CRUD命令的视图才能有效地显示:
<option>Title: Subtitle</option>
但我不知道如何让FormHelper这样做。有人可以为此通用形式提供策略(即:
echo $this->Form->input('title', array(
//whatever option(s) solve this
));
非常感谢解决方案或建议!
答案 0 :(得分:1)
使用Set
类:
$results = $this->Model->find('all');
$options = Set::combine($results, '{n}.Model.id', array('{0}: {1}', '{n}.Model.title', '{n}.Model.sub_title'));
所以你的选项数组看起来像
array(
0 => 'Title: sub title',
1 => 'Title: different sub'
);
并设置下拉列表以使用这些选项
$this->Form->input('title', array('options' => $options));