CakePHP 2.0 $ this-> Form-> input() [英] CakePHP 2.0 $this->Form->input()
本文介绍了CakePHP 2.0 $ this-> Form-> input()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的add.tcp
...
This is my add.tcp ...
<?php
echo $this->Form->create('Group');
echo $this->Form->input('group_id', array('label' => 'ID'));
echo $this->Form->input('group_desc', array('label' => 'Group Description'));
echo $this->Form->end('Save');
?>
表名:groups
表字段:group_id,group_desc
PK:group_id
Table name: groups Table fields: group_id, group_desc PK: group_id
这是我的控制器
...
This is my controller ...
class GroupsController extends AppController {
public $helper = array('Html', 'Form', 'Session');
public $components = array('Session');
public function add() {
if ($this->request->is('post')) {
if ($this->Group->save($this->request->data)) {
$this->session.setFlash('');
$this->redirect(array('action' => 'index'));
}
}
}
}
我在浏览器上显示这个视图,没有字段group_id,但是有group_desc,HTML源代码看起来像这样
...
When I display this view on the browser, there was nothing for the field group_id but there was for the group_desc, the HTML source for the look like this ...
<form action="/cakephp/index.php/groups/add" id="GroupAddForm" method="post" accept-charset="utf-8" name="GroupAddForm">
<div style="display:none;">
<input type="hidden" name="_method" value="POST">
</div><input type="hidden" name="data[Group][group_id]" id="GroupGroupId">
<div class="input text">
<label for="GroupGroupDesc">Group Description</label><input name="data[Group][group_desc]" maxlength="15" type="text" id="GroupGroupDesc">
</div>
<div class="submit">
<input type="submit" value="บันทึก">
</div>
</form>
为什么被隐藏?
推荐答案
CakePHP自动确定您不希望用户手动输入ID,因此会为您隐藏ID。
CakePHP automagically determines that you do not want a user to manually enter an ID, as such hides it for you.
要强制显示ID字段,请将类型
设置为文本
:
If you would like to force ID field to be shown, set the type
to text
:
echo $this->Form->input('group_id', array('type' => 'text', 'label' => 'ID'));
这篇关于CakePHP 2.0 $ this-> Form-> input()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文