views:

31

answers:

1

Hey guys, I'm working on a cakephp app that manages a list of alpha users. It's a simple form that accepts a name and email and then generates an alpha code after submission, that alpha code is then stored in the record with the name and email under the column "code." I'm using a component calleed PasswordHelper which is located here

Here' my code

class AlphaUsersController extends AppController {
    var $name = 'AlphaUsers';
    var $components = array('PasswordHelper');

    function add() {
      if(!empty($this->data)) {
         if($this->AlphaUser->save($this->data)){
             $this->AlphaUser->set('code', generatePassword(10));
             $this->AlphaUser->save();
             $this->Session->setFlash('User has been added.');
             $this->redirect(array('action' => 'index'));
         }
      }
    }
}

The form data saves just fine when I don't include the alpha code lines, but when I try to generate the password, I get this error.

Fatal error: Call to undefined function generatepassword() in /Users/Warren/Sites/caroverload/app/controllers/alpha_users_controller.php on line 22

What's going on here? I have the PasswordHelper file saved in the appropriate components directory and it's added in the components array for this controller.

+2  A: 

I think the way you are calling the PasswordHelper methods should look more like this: $this->PasswordHelper->generatePassword(10).

As you have it now, it is looking for that as a global function, which doesn't exist and throws the error.

Jason McCreary
+1 that's definitively at least one of the issues :-)
jdehaan
That's the only issue! Thanks!
wcolbert
Correction: It's looking for a global function `generatePassword`, not a local method.
deceze
@deceze, good catch. I have updated the answer per your correction.
Jason McCreary