CakePHP 中的下拉选择列表 [英] Dropdown select list in CakePHP

查看:25
本文介绍了CakePHP 中的下拉选择列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何在 CakePHP 中从不同的视图中选择一个镜头的内容吗?

Does anybody know how to select the contents of one take from a different view in CakePHP?

我有一个 itemgroups,它有 2 个字段 IDDescription.我需要在项目添加页面中创建一个向下列表,但我找不到将另一个表中的所有值放入数组以放入页面的好方法.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆