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

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

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建