我有以下代码:
<h2>Add System</h2>
<?php
echo $this->Form->create('ReleaseServer');
echo $this->Form->input('server_name',array('error'=>array(
0 => 'Please choose a system name'),
'label'=>'System Name'
));
echo $this->Form->input('server_id', array('label'=> 'System ID'));
echo $this->Form->select('server_environment', $environments, null, array(
'empty' => "-- Select an Environment --",
'label' => "Select an Environment",
'error' => array(0 => 'Please choose an environment!'),
'onchange'=>'console.log(this.value);'
)
);
echo $this->Form->end('Save System');
?>
由于某些原因echo $this->Form->input('server_id', array('label'=> 'System ID'));
无论我把它放在哪里,它都会显示为一个选择框。
如何解决这个问题?
您可以尝试将type
添加到您的选项数组中,并显式定义您想要的输入。
编辑
在深入研究了Cake API之后,我想我可能已经找到了可能影响您的特定代码行。
if (preg_match('/_id$/', $fieldKey) && $options['type'] !== 'hidden') {
$options['type'] = 'select';
}
看起来你很可能触发这个if
条件。如果是这样,您唯一的选择是显式地在您的选项数组中设置type
属性。
现在我正在使用一个hack:
echo $this->Form->input('server_id', array('label'=> 'System ID',
'type'=>'text'));
我明确地将type
设置为文本。
对于其他输入,我不必这样做,但这可能是必须的方式
如果显示或不显示无关紧要,就隐藏输入。当插入mysql时,它将分配一个新的id。
echo $this->Form->input('server_id', array('type'=> 'hidden'));