CakePHP select default value in SELECT input(CakePHP 在 SELECT 输入中选择默认值)
问题描述
使用 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 输入中选择默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CakePHP 在 SELECT 输入中选择默认值
 
				
         
 
            
        基础教程推荐
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- php中的foreach复选框POST 2021-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- php中的PDF导出 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- 将变量从树枝传递给 js 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
				 
				 
				 
				