我正在使用 Yii afterdelete() 来更新在另一个表中删除的相关数据。这是我在控制器中的代码:
控制器动作
public function actionDelete($id)
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadModel($id)->delete();
// 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'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
模型功能
protected function afterDelete()
{
parent::afterDelete();
$show_model = new Show();
$show_model = Show::model()->findAll('tbl_season_id='.$this->id);
$show_model->updateAll('tbl_season_id = NULL, on_season=0');
}