erj*_*ang 16 php cakephp helpers relationships cakephp-2.x
使用CakePHP:
我有多对一的关系,让我们假装它是很多叶子到树.当然,我烘焙了一个表单来向树中添加一个Leaf,你可以使用表单助手创建的下拉框(标记)指定它是哪个树.
唯一的一点是,SELECT框始终默认为Tree#1,但我希望它默认为它被添加到的树:
例如,调用example.com/leaf/add/5
将调出接口以向树#5添加新的Leaf.Leaf.tree_id
默认为"Tree 5" 的下拉框,而不是它当前默认为"Tree 1".
我需要在Leaf控制器和Leaf view/add.ctp
中执行此操作吗?
Rya*_*yan 52
在CakePHP 1.3中,用于'default'=>value
选择选择输入中的默认值:
$this->Form->input('Leaf.id', array('type'=>'select', 'label'=>'Leaf', 'options'=>$leafs, 'default'=>'3'));
Run Code Online (Sandbox Code Playgroud)
小智 20
你永远不应该使用select()
,或者text()
,或者radio()
等; 这是一种可怕的做法.你应该使用input()
:
$form->input('tree_id', array('options' => $trees));
Run Code Online (Sandbox Code Playgroud)
然后在控制器中:
$this->data['Leaf']['tree_id'] = $id;
Run Code Online (Sandbox Code Playgroud)
$this->Form->input('Leaf.id', array(
'type'=>'select',
'label'=>'Leaf',
'options'=>$leafs,
'value'=>2
));
Run Code Online (Sandbox Code Playgroud)
这将从$ leafs中的选项列表中选择默认的第二个索引位置值.
归档时间: |
|
查看次数: |
109387 次 |
最近记录: |