cakepp控制器的add函数存在问题


cakephp controller problems with the add function

在将用户输入用户表时遇到问题。我去。。users/add,我的表单将按预期显示。我填写了表格并点击了提交按钮,但什么也没发生。屏幕闪烁,显然什么也没做。数据库表中没有名为users的新记录。

我可以在..查看所有现有的用户记录。。users/index,所以一切都连接好了。有什么想法吗?

控制器

<?php 
 class UsersController extends AppController {
public $helpers = array('Html', 'Form', 'Session');
public $components = array('Session');
public function index() {
    $this->set('users', $this->User->find('all'));
}
public function add() {
    if ($this->request->is('user')) {
        $this->User->create();
        if ($this->User->save($this->request->data)) {
            $this->Session->setFlash(__('User has been created.'));
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('Unable to create the user.'));
        }
    }
}
 }

?>

提前付款。DS

我不知道你使用的是哪个版本的CakePHP,但根据CakePHP 2.0文档,没有这样的内置检测器user。尝试更改

$this->request->is('user')

$this->request->is('post')

参考:http://book.cakephp.org/2.0/en/controllers/request-response.html