0

I am trying to set up a "forgot password" system. User enters email and if it exists a new email is recorded and sent to the user email address entered. The user email check works ok. When trying to enter a new passord into system it does not.

The code is this:

..... (form is_valid and check email ok)

if(is_object($object)) {

        $newpassword = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',8)),0,8);

        $input = $form->getValues();

        $user = Doctrine::getTable('Tcc_Model_User')
            ->find($input['email']);

        $user->fromArray($input);
        $user->Password = md5($newpassword);
        $user->save();
......
email send

} else {
    $form->getElement('email')->addError('Sorry, there is no record of that email adddress.');
  }

the error I get is this:

Call to a member function fromArray() on a non-object

Could someone help me figure out what I am doing wrong? Please.

2 Answers 2

6

Simply put, $user is not an object. It's probably either false or null, signifying that find() did not actually find what it was looking for.

You can see what $user actually is with var_dump($user), and then you should read the documentation for find to see why it's returning that.

Sign up to request clarification or add additional context in comments.

11 Comments

Or the Zend way with: Zend_Debug::dump($user); :)
But $user id the result of Doctrine::getTable('Tcc_Model_User')->find($input['email']); so it's maybe a row (Zend Framework) and not an object of user's class.
@JBRTRND-DEV: There is no object of class user involved here. The intent of the code is clear: find the row with the specified email, update its other fields based on input, and save it. There's no user object logically involved in this.
@Jon : I agree, here there's no class or object "user" but what I tried to explain, is that $user is already affected (row, array, boolean, null) by ->find() function, and in this way, $user->fromArray doesn't work.
@JBRTRND-DEV: $user is the result of the find function, it's not affected by it.
|
0

According to the docs, Doctrine_Table::find() (called on the line above your error) returns one of the following entities:

Doctrine_Collection, array, Doctrine_Record or false if no result

This means that you need to check what was returned before you try and use the value, $user, as if it were an object exposing the fromArray() method.

3 Comments

Isn't if(is_oject($object) telling me that is returning a value?
You also need if (is_object($user)), since it is the $user variable that is triggering the error.
So as @JBRTRND-DEV says if find() only works on primary key that could be the problem. Also because the very same code works ok in other situations

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.