Raheel Hasan
Raheel Hasan

Reputation: 6013

symfony 1.4 - doctrine save() method: how to identify success

Can someone please tell me how to know if the save() method was successful or not. I tried to find out if it returned true/false, but it returns null.

for example:

$contact_obj->save();

How to know that it worked?

Upvotes: 1

Views: 2318

Answers (2)

rohitcopyright
rohitcopyright

Reputation: 342

you can check by $contact_obj->getId() function, it will return the inserted id on success.

Upvotes: 0

sinhix
sinhix

Reputation: 863

If you use Doctrine, try trySave():

abstract class Doctrine_Record {

    ...

    /**
     * tries to save the object and all its related components.
     * In contrast to Doctrine_Record::save(), this method does not
     * throw an exception when validation fails but returns TRUE on
     * success or FALSE on failure.
     *
     * @param Doctrine_Connection $conn                 optional connection parameter
     * @return TRUE if the record was saved sucessfully without errors, FALSE otherwise.
     */
    public function trySave(Doctrine_Connection $conn = null) {
        try {
            $this->save($conn);
            return true;
        } catch (Doctrine_Validator_Exception $ignored) {
            return false;
        }
    }
}

Upvotes: 3

Related Questions