【发布时间】:2013-09-11 06:54:00
【问题描述】:
我创建了一个这样的函数来删除记录:
echo $this->Form->postLink('<i class="icon-trash icon-white"></i>',
array('action' => 'delete',$distance['Distance']['id'], 'Distance'),
array('confirm' => 'Are you sure?', 'class' => 'btn btn-danger', 'escape' => false));
它应该在传递两个参数的控制器中调用函数delete。
但我在 chrome 控制台中遇到这种类型的错误:
cakephp 对象 # 没有方法 'submit'
以前它可以工作,现在删除按钮有时可以工作,有时不能。
控制器代码是:
public function delete($id, $model) {
$this->loadModel($model);
$this->Session->setFlash($id +" " + $model);
if ($this->request->is('get')) {
throw new MethodNotAllowedException();
}
if ($this->$model->delete($id)) {
$this->Session->setFlash('The item has been deleted');
if($model == "Project" || $model == "Car"){
$this->redirect(array('action' => 'preferences'));
}else{
$this->redirect(array('action' => $model.'s'));
}
}
}
【问题讨论】:
-
这里有什么问题,对我来说很好
-
问题是控制器中的删除函数没有被调用,因为我认为这个错误
-
我可以看看你的控制器代码
-
确定您没有在表单中使用 postLink()?
-
好吧,我已经添加了表单: Form->create();?> 以及 Form->end(); ?> 但这无济于事
标签: cakephp