如何在cakephp中为select标签定义id?

时间:2014-05-13 05:22:03

标签: cakephp-2.3

用于制作选择标签的我的cakephp代码是

<?php echo $this->Form->select('User.country_id',array($countries),null,array('id'=>'selection','empty'=>null,'label'=>false,'style'=>'width:231px'));?>

这里我定义了id ='selection',但是当我在浏览器中检查这个下拉框时,它显示的是id ='UserCountryId'。这是怎么回事?由于这个原因,我的jquery和javascript无法正常工作。

3 个答案:

答案 0 :(得分:1)

我认为你的语法不正确。它应该是:

<?php
    echo $this->Form->input('User.country_id', array(
        'type'=>'select,
        'options'=>array($countries), // this is probably not needed 
        'id'=>'selection',
        'empty'=>null,
        'label'=>false,
        'style'=>'width:231px'
    ));
?>

答案 1 :(得分:1)

您可以使用以下代码

<?php 

echo $this->Form->input('User.country_id',array('type'=>'select','options'=>$countries,'id'=>'selection'));

?>

答案 2 :(得分:1)

如果你需要Id使用cake php语法

<?php
echo $this->Form->input('User.country_id', array(
    'type'=>'select, 
    'id'=>'selection',
    'style'=>'width:231px'
));
?>

你的jquery和javascript会运行试试这个