CakePHP中的下拉列表 [英] Dropdown select list in CakePHP
本文介绍了CakePHP中的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何从CakePHP中的不同视图中选择一个镜头的内容吗?
Does anybody know how to select the contents of one take from a different view in CakePHP?
我有一个镜头 itemgroups
有两个字段 ID
和描述
。我需要在项目添加页面中创建一个向下的列表,但是我找不到一个很好的方法将所有的值从另一个表到一个数组放入页面。
I have a take itemgroups
that has 2 fields ID
and Description
. I need to make a down down list in the item add page but I can not find a good way to get all of the values from another table into an array to put into the page.
下面我也列出了每个模型。
Below I have also listed my models for each.
<?php
class Item extends AppModel
{
var $name = 'Item';
var $belongsTo = 'Itemgroup';
}
?>
class Itemgroup extends AppModel
{
var $name = 'Itemgroup';
var $hasOne = array('Item');
var $validate = array(
'description' => array(
'rule' => 'notEmpty'
),
'description' => array(
'rule' => 'notEmpty'
)
);
}
?>
推荐答案
假设您的模型是User和您想要的字段使用是美国各州(例如)的列表...
Assuming your model is User and the field you want to use is a list of US states (for example)...
在您的控制器中:
$this->set('states',$this->State->find('list'));
并在您的视图中:
<?php echo $form->input('User.state',array('type'=>'select','options'=>$states)); ?>
这篇关于CakePHP中的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文