1
votes

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?

2

2 Answers

3
votes

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;
        }
    }
}
0
votes

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