Hi,
I need to call the a function after deleting a record
The model
protected function afterDelete()
{
parent::afterDelete();
Tags:tagDelete($id);
}
controller
public function actionDelete($id)
{
$this->loadModel($id)->delete();
Tags:tagDelete($id);
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
The tag model
public static function tagDelete($entity_id){
//find the tag
$tags = Yii::app()->db->createCommand()
->select('*')
->from('tagged')
->where("entity_id = $entity_id")
->queryRow();
var_dump($tags);
// Get the tag data
$tagData = Yii::app()->db->createCommand()
->select('count')
->from('tags')
->where('tag="'.$tags["tag"].'"')->queryRow();
var_dump($tagData);
// update the tag counter
Yii::app()->db->createCommand()
->update('tags', array('count'=>$tagData['count']-1), 'id=:id',array('id'=>$tags["id"]) );
//Delete the tag
Yii::app()->db->createCommand()
->delete('tagged','entity_id=:id', array('id'=>$entity_id) );
}
The tagDelete() works with no problem, but it been called after the post is deleted.
What to do?
THX