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

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

Open
mescalito opened this issue Mar 15, 2012 · 4 comments

Comments

@mescalito
Copy link

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'] = '[email protected]';
                        $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! :)

@steinkel
Copy link
Collaborator

Hi. Did the save returned validation errors ?

El 15 de marzo de 2012 23:47, mescalito <
[email protected]

escribi:

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'] = '[email protected]';
$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! :)


Reply to this email directly or view it on GitHub:
#52

@steinkel
Copy link
Collaborator

don't worry about payments :)

Are you including the USer model in the $uses of your ItemsController ?

El 16 de marzo de 2012 21:06, mescalito <
[email protected]

escribi:

Hi, Steinkel, thanks for your time!!!!!!!

the error I getting is:
Notice (8): Undefined property: AuthsomeComponent::$User
[APP\controllers\items_controller.php, line 57]

Code | Context
//$result = $this->User->save($data);
$result = $this->Authsome->User->save($data);
$data = array(
"User" => array(
"id" => null,
"username" => "johnsmith1234",
"password" => "123456",
"confirm_password" => "123456",
"email" => "[email protected]",
"first_name" => "John",
"last_name" => "Smith",
"user_group_id" => "2"
)
)
ItemsController::create1() - APP\controllers\items_controller.php, line 57
( ! ) Fatal error: Call to a member function save() on a non-object in
C:\wamp\www\flipxingUsers\app\controllers\items_controller.php on line 57

Because I know you time is precious, I was wondering if you want me to pay
you this consultation, Paypal can work

Thank you so much!


Reply to this email directly or view it on GitHub:
#52 (comment)

@mescalito
Copy link
Author

No I don't! what line of code should I put in the controller? (de donde eres?)

@steinkel
Copy link
Collaborator

soy espaol ;)
El 16/03/2012 21:18, "mescalito" <
[email protected]>
escribi:

No I don't! what line of code should I put in the controller? (de donde
eres?)


Reply to this email directly or view it on GitHub:
#52 (comment)

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