Elorfin
Elorfin

Reputation: 2497

symfony 1.4 : problem method isDeleted()

I want to test if an object is deleted after a calling to my function executeDelete in order to send to the user an error if the object is still in my database.

if ($logement->isDeleted()) {
  $this->getUser()->setFlash('notice', 'Suppression du logement effectuée');
}
else {
  $this->getUser()->setFlash('error', 'Erreur lors de la suppression du logement');
}

But I have an error :

Unknown method Logement::isDeleted

I don't find how to use this method, and I think it's the problem I have.

Upvotes: 0

Views: 672

Answers (1)

Darragh Enright
Darragh Enright

Reputation: 14136

You might have to show us more code... But basically your method does not exist, and you would have to create it.

I assume you're using Doctrine. Assuming that you are deleting the record like so:

$lodgement->delete();

Doesn't the delete method return a boolean to indicate success/failure? So you could simply do the following:

if ($lodgement->delete()) {
    $this->getUser()->setFlash('notice', 'success');
} else {
    $this->getUser()->setFlash('error', 'failure');
}

EDIT

If you wanted to implement a isDeleted() method you could use the postDelete() hook. In your model class:

class Lodgement extends BaseLodgement
{
    // add an 'isDeleted' property
    protected $isDeleted = false;

    // override the postDelete method
    public function postDelete($values)
    {
        $this->isDeleted = true;
    }

    // define your own isDeleted method
    public function isDeleted()
    {
        return $this->isDeleted;    
    }
}

Then you can do this:

$lodgement->delete();
echo $lodgement->isDeleted() ? 'notice' : 'error';

Upvotes: 1

Related Questions