In my project I need to implement the following functionality: - when user decides to delete its account, before deletion, an email with a '$deletionUrl' should be sent to that user in order to confirm the decision by email. I'm using Yiimailer extension and it's working fine. However, I'm not sure where and how I should put these conditions regarding deletion of user. This is my actionDelete:
public function actionDelete($id)
{
$this->loadModel($id)->delete();
if (!isset($_GET['ajax'])) {
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
}
I was researching on internet and found that CActiveRecord has a protected method beforeDelete ()
protected function beforeDelete()
{
if($this->hasEventHandler('onBeforeDelete'))
{
$event=new CModelEvent($this);
$this->onBeforeDelete($event);
return $event->isValid;
}
else
return true;
}
http://www.yiiframework.com/doc/api/1.1/CActiveRecord#beforeDelete-detail
But not sure how to adapt it to my case. And is there other way to do this?