【问题标题】:cakephp controller problems with the add functioncakephp控制器的add函数问题
【发布时间】:2013-08-10 17:40:43
【问题描述】:

在将用户输入用户表时遇到问题。 我去 ..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

【问题讨论】:

    标签: php cakephp add


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 谢谢朋友。我更改它是因为我认为它是 post 模型的一部分,所以我将其更改为 user 作为用户模型的一部分。好东西,嗯? DS
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多