Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save() #3555

Closed
ghost opened this issue May 23, 2014 · 1 comment
Closed

save() #3555

ghost opened this issue May 23, 2014 · 1 comment
Milestone

Comments

@ghost
Copy link

ghost commented May 23, 2014

i'm trying to save data using save() in cakkephp 2.4.6 code as below:
Controller:

public function add() {
        if ($this->request->is('post')) {
            $this->User->create();
            debug($this->request->data);
            if ($this->User->save($this->request->data)) {
                $this->Session->setFlash(__('New user has been saved'));
                //return $this->redirect(array('action' => 'index'));
            }
            $this->Session->setFlash(
                __('User could not be saved. Please, try again.')
            );
        }
    }

Model:

public function beforeSave($options = array()) {
        if (isset($this->data[$this->alias]['password'])) {
            $passwordHasher = new SimplePasswordHasher();
            $this->data[$this->alias]['password'] = $passwordHasher->hash(
                $this->data[$this->alias]['password']
            );
        }
        return true;
    }

debug:

array(
    'submit' => '',
    'add' => array(
        'password' => '*****',
        'firstName' => 'Test',
        'middleName' => '',
        'lastName' => 'me',
        'role' => '3',
        'email' => 'test@abc.com',
        'confirmPassword' => 'a'
    )
)

table:

`id`
`first_name`
`middle_name`
`last_name`
`role`
`email`
`password`
`last_login`
`status`

Swing Error:
Error: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (tbcs.users, CONSTRAINT role_fk FOREIGN KEY (role) REFERENCES roles (id) ON UPDATE CASCADE)

SQL Query: INSERT INTO tbcs.users (status) VALUES (1)

@ADmad
Copy link
Member

ADmad commented May 23, 2014

This is not a help forum. The ticket tracker is reserved for possible
bugs and feature enhancements to the CakePHP framework. If you are
looking for help on how to implement a feature or to better understand
how to use the framework correctly, please visit one of the following:

The CakePHP Manual
The CakePHP online API
The CakePHP Google Group
Stackoverflow

or the #cakephp channel on irc.freenode.net, where we will be more than
happy to help answer your questions.

Thanks!

@ADmad ADmad closed this as completed May 23, 2014
@markstory markstory added this to the 2.5.2 milestone May 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants