0

using cakePhp for an existing product they have old version 1.2. I just started using CakePhp. I tried to save some data to the table. here is my code.

function add(){

        //echo $id;
        pr($this->data);
        if(!empty($this->data)){
            $this->User->create();
            if($this->User->save($this->data)){
                debug($this->User->validationErrors);
                exit();
                $this->Session->setFlash("Data saved man");
                $this->redirect(array('action'=>'index',2));
            }
        }
    }

Below is debug data.

Array
(
    [user] => Array
        (
            [first_name] => hello
            [last_name] => man
            [email] => lrer@drei.cm
            [password] => 123
            [created_at] => Array
                (
                    [month] => 01
                    [day] => 17
                    [year] => 2014
                    [hour] => 08
                    [min] => 56
                    [meridian] => am
                )

            [modified_at] => Array
                (
                    [month] => 01
                    [day] => 17
                    [year] => 2014
                    [hour] => 08
                    [min] => 56
                    [meridian] => am
                )

        )

)
app\controllers\users_controller.php (line 36)
Array
(
)

(default) 0 query took ms
Nr  Query   Error   Affected    Num. rows   Took (ms).

I have no clue why data is not saving to database. I need to get it work for version 1.2. thanks

lokeshjain2008
  • 1,879
  • 1
  • 22
  • 36
  • I accept this is due to carelessness, but I left this question here as I see many of my friends repeating the same error as mine. – lokeshjain2008 Jan 17 '14 at 09:23
  • This may be helpful in this type of scenario . http://stackoverflow.com/questions/566508/how-to-debug-when-cakephp-modelsave-doesnt-attempt-an-insert – lokeshjain2008 Jan 17 '14 at 09:38

1 Answers1

3

I think user key should have capital U as User. Check your view code to make sure that the model passed to $form->create('User') not 'user'

Hazem Mohamed
  • 564
  • 3
  • 7