CRUD command生成的代码删除不成功?

views:

[<?php echo CHtml::linkButton('删除歌曲',array('submit'=>array('delete','id'=>$music->musicId),'confirm'=>'你确定要删除吗?')); ?>


]

MusicController:

 public function actionDelete()


    {


        if (Yii::app ()->request->isPostRequest)


        {


        // we only allow deletion via POST request


            $this->loadMusic()->delete ();


            $this->redirect ( array ('list' ) );


        }


        else


            throw new CHttpException ( 500, 'Invalid request. Please do not repeat this request again.' );


    }


     */


    public function loadMusic($id = null)


    {


        if ($this->_music === null)


        {


            if ($id !== null || isset ( $_GET ['id'] ))


                $this->_music = Music::model ()->findByPk ( $id !== null ? $id : $_GET ['id'] );


            if ($this->_music === null)


                throw new CHttpException ( 500, 'The requested music does not exist.' );


        }


        return $this->_music;


    }


为什么我一直删除不成功,在model 的beforeDelete和afterDelete里都可以删除成功了,可就是actionDelete删除不了,但依然会执行到 $this->redirect ( array ('list' ) );这个语句。

哪个可以帮忙?谢谢!

你的beforeDelete函数是怎么样的?有没有记得返回值?

谢谢强的回复。

model里的:

 


protected function beforeDelete()


    {


         MusicCategoryAssociation::model()->deleteAll('musicId='.$this->musicId);


    }


可是这个表删除记录成功了

是不是每个before,after相关的方法体内都要返回boolean值,并且调用父类的实现呢?

错了,应该只有beforeDelete,beforeSave才能返回boolean值true,

但我还是有点疑问,调用parent::beforeDelete或parent::beforeSave或parent::afterSave有什么效果呢?

确保父类的代码被调用。你可以看看CActiveRecord这些方法的实现。