Skip to content

Simple question please: how to create a new user from regular controller #52

@mescalito

Description

@mescalito

Hi Steinkel, how are you? I hope everything is ok.
I have a question, maybe you can help me...

I was wondering how to add a new user from a regular controller?

I have a controller for items (app/controllers/items_controller.php) and I want to create an user from there, how can I do that?

I tried something like this but is not working, can you give me a hand, please

        class itemController extends AppController {
            public function add() {
                $this->Item->create();
                if ($this->Item->save($this->data)) {
                    // create/save new user
                        $data['User']['id'] = null;
                        $data['User']['username'] = 'johnsmith1234';
                        $data['User']['password'] = '123456';
                        $data['User']['confirm_password'] = '123456';
                        $data['User']['email'] = 'jed@bodegasale.com';
                        $data['User']['first_name'] = 'John';
                        $data['User']['last_name'] = 'Smith';
                        $data['User']['user_group_id'] = '2';

                        $result = $this->User->save($data);
                }
            }
        }

Thanks for your time! :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions