CakePHP选择输入:设置显示成员和值成员可能吗? [英] CakePHP select input : is setting a display member and a value member possible?

查看:149
本文介绍了CakePHP选择输入:设置显示成员和值成员可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个表单输入:

echo $this->Form->input('category_id',array('label'=>'Catégorie','type'=>"select",'options'=>$categories,'empty'=>false));

现在,$类别填充了这些信息:

Now, $category is filled with those informations:

Array
(
[0] => Array
    (
        [categories] => Array
            (
                [id] => 1
                [nom] => Autre
            )

    )

[1] => Array
    (
        [categories] => Array
            (
                [id] => 2
                [nom] => Véhicule
            )

    )

[2] => Array
    (
        [categories] => Array
            (
                [id] => 3
                [nom] => Audio/video
            )

    )

)



我希望Select输入仅显示nom字段(名称),但在提交表单时发送ID 。这是可能在CakePHP吗?我已经通过谷歌和CakePHP的文档和论坛爬过一段时间没有成功: - /

I would like that the Select input shows only the "nom" field (name), but that it sends the ID when the form is submitted. Is that possible in CakePHP? I've been crawling through Google and CakePHP's doc and forums for a while without success :-/

先感谢你们,有一个愉快的一天!

Thank you in advance guys and have a nice day!

推荐答案

Cakephp使用单维数组来选择选项。您将您的值更改为单维度,ID为您的键,nom为选项标签的文本,然后将其传递给选项键:

Cakephp uses a single dimension array for select options. You change your your to single dimension with id as your key and nom as text of option tag and then pass it to options key:

$categories = Set::combine($categories,'{n}.categories.id','{n}.categories.nom');

这篇关于CakePHP选择输入:设置显示成员和值成员可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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