使用 CakePHP:
Using CakePHP:
我有一个多对一的关系,让我们假设它是许多叶子到树.当然,我烘焙了一个表单,将一个叶子添加到一棵树中,您可以通过表单助手创建的下拉框(标签)指定它是哪个树.
I have a many-to-one relationship, let's pretend it's many Leafs to Trees. Of course, I baked a form to add a Leaf to a Tree, and you can specify which Tree it is with a drop-down box ( tag) created by the form helper.
唯一的问题是,SELECT 框始终默认为 Tree #1,但我希望它默认为要添加到的 Tree:
The only thing is, the SELECT box always defaults to Tree #1, but I would like it to default to the Tree it's being added to:
例如,调用 example.com/leaf/add/5 会调出界面,将新的叶子添加到树 #5.Leaf.tree_id 的下拉框将默认为Tree 5",而不是当前默认为Tree 1".
For example, calling example.com/leaf/add/5 would bring up the interface to add a new Leaf to Tree #5. The dropdown box for Leaf.tree_id would default to "Tree 5", instead of "Tree 1" that it currently defaults to.
我需要在我的 Leaf 控制器和 Leaf view/add.ctp 中放入什么来做到这一点?
What do I need to put in my Leaf controller and Leaf view/add.ctp to do this?
你不应该使用 select(), or text(), or radio() 等;这是可怕的做法.你应该使用 input():
You should never use select(), or text(), or radio() etc.; it's terrible practice. You should use input():
$form->input('tree_id', array('options' => $trees));
然后在控制器中:
$this->data['Leaf']['tree_id'] = $id;
这篇关于CakePHP 在 SELECT 输入中选择默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
不能使用 'Object 作为类名,因为它是保留的Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作为类名,因为它是保留的 Cake 2.2.x)
OAuth 重定向后会话丢失Session is lost after an OAuth redirect(OAuth 重定向后会话丢失)
Cakephp 3.x 中的分页排序Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分页排序)
CakePHP 多个应用程序的共享核心CakePHP Shared core for multiple apps(CakePHP 多个应用程序的共享核心)
在 CakePHP 3 上登录 [ Auth->identify() ] 始终为 falLogin [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登录 [ Auth-identify() ] 始终为 false)
致命错误:允许的内存大小为 134217728 字节已用尽Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命错误:允许的内存大小为 134217728 字节已用尽