firefiter
firefiter

Reputation: 96

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

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.

Upvotes: 0

Views: 1477

Answers (2)

DaveRandom
DaveRandom

Reputation: 88697

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.

Upvotes: 0

Jon
Jon

Reputation: 437474

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.

Upvotes: 6

Related Questions