简体   繁体   中英

cakephp controller problems with the add function

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM