dstewart101
dstewart101

Reputation: 1112

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

Upvotes: 0

Views: 970

Answers (1)

Konsole
Konsole

Reputation: 3475

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

Upvotes: 2

Related Questions