0

我有这个表单输入:

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

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

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 中可能吗?我已经在 Google 和 CakePHP 的文档和论坛中爬行了一段时间,但没有成功:-/

提前谢谢你们,祝你们有美好的一天!

4

2 回答 2

1

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

$categories = Set::combine($categories,'{n}.categories.id','{n}.categories.nom');
于 2012-07-27T17:36:02.627 回答
0

你应该尊重 Cakephp 的约定。在你的数据库中用“name”替换“nom”,如果你的关联做得很好,cakephp 会自动完成。

于 2012-07-27T17:38:10.040 回答