我用crud生成的my_messageController,在执行delete里,在admin里可以执行,可是在list中死活执行不了,我的list中的delete是copyadmin中的,为什么啊,郁闷了一上午,大家救我啊
我用crud生成的my_messageController,在执行delete里,在admin里可以执行,可是在list中死活执行不了,我的list中的delete是copyadmin中的,为什么啊,郁闷了一上午,大家救我啊
我在list页是可以得到id的,可是在controller里为什么就不可以哪
你最好能贴一下code, controller and view.
你觉得可以检查一下delete使用的方法,注意CHtml::link 和CHtml::linkButton的区别。
list中的代码是这样的
<?php echo CHtml::linkButton('Delete',array(
'submit'=>'',
'params'=>array('command'=>'delete','id'=>$model->id),
'confirm'=>"你确定要删除吗? #{$model->id}"));
?>
my_messageController中为下面的
protected function processAdminCommand()
{
if(isset($_POST['command'], $_POST['id']) && $_POST['command']==='delete')
{
// echo '########';
// exit;
$this->loadmy_message($_POST['id'])->delete();
// reload the current page to avoid duplicated delete actions
$this->refresh();
}
}
public function loadmy_message($id=null)
{
if($this->_my_message===null)
{
echo $_GET['id'];
if($id!==null || isset($_GET['id']))
$this->_my_message=my_message::model()->findbyPk($id!==null ? $id : $_POST['id']);
if($this->_my_message===null)
throw new CHttpException(500,'The requested my_message does not exist.');
}
return $this->_my_message;
}
public function actionDelete()
{
$this->processAdminCommand();
if(Yii::app()->request->isPostRequest)
{echo "ssssssssssssss";
exit;
// we only allow deletion via POST request
$this->loadmy_message()->delete();
$this->redirect(array('list'));
}
else
throw new CHttpException(500,'Invalid request. Please do not repeat this request again.');
}
你的list方法在哪里?对应的view呢?
嘻嘻,解决了,一直没回