doulierong0334 2013-08-10 17:40 采纳率: 100%
浏览 17
已采纳

cakephp控制器的add函数问题

Having problems getting a user entered into a users table. I go to ..users/add and my form appears as expected. I fill in the form and hit the submit button but nothing happens. The screen flickers and apparently does nothing. No new record appear in the database table called users.

I can view all the exisiting user records at ..users/index so it's all hooked up ok. Any thoughts anyone?

The controller

<?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.'));
        }
    }
}
 }

?>

THanks in advance. DS

  • 写回答

1条回答 默认 最新

  • dsmvovm27249 2013-08-10 17:55
    关注

    I don't know which version of CakePHP you are using but according to CakePHP 2.0 documentation there is no such built in detector called user. Try changing

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

    To

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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于php中URL传递GET全局变量的问题
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件