gpt4 book ai didi

CakePHP 2.0 $this->Form->input()

转载 作者:行者123 更新时间:2023-12-05 08:59:40 24 4
gpt4 key购买 nike

这是我的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');

?>

表名:组表字段:group_id、group_descPK: group_id

这是我的 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'));
}
}
}
}

当我在浏览器上显示此 View 时,字段 group_id 没有任何内容,但有 group_desc,HTML 源看起来像这样...

<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 字段,请将 type 设置为 text:

echo $this->Form->input('group_id', array('type' => 'text', 'label' => 'ID'));

关于CakePHP 2.0 $this->Form->input(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11684596/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com