【发布时间】:2011-12-23 13:58:39
【问题描述】:
我似乎无法让我的编辑类工作。我的验证工作正常,当我在点击编辑按钮后使用 debug($this->data) 时,所有显示的数据都是完美的,但没有更新表格。
这是我的编辑类。
public function edit($id = null) {
if($this->request->is('get')) {
$this->request->data = $this->Bookmark->read(null, $id);
} else {
if($this->Bookmark->saveAll($this->request->data)) {
$this->Session->setFlash('The bookmark has been saved!');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('The bookmark could not be saved. Please, try again.');
}
}
}
这是视图。
<?php
echo $this->Form->create('Bookmark', array(
'action' => 'edit',
'inputDefaults' => array(
'class' => 'input-text'
)
));
echo $this->Form->inputs(array(
'legend' => false,
'fieldset' => true,
'Bookmark.title',
'Url.url',
'Bookmark.id' => array('type' => 'hidden'),
'Url.id' => array('type' => 'hidden')
));
echo $this->Form->button('Edit');
echo $this->Form->end();
?>
我已经更新了我的编辑类,但这仍然没有解决我的错误。修复它的是我添加到视图中的两个隐藏字段。
'Bookmark.id' => array('type' => 'hidden'),
'Url.id' => array('type' => 'hidden')
不太清楚为什么,但我在网上查看了其他一些编辑视图并尝试了这个,现在它可以工作了。
【问题讨论】:
标签: cakephp cakephp-2.0