gpt4 book ai didi

mysql - 如何删除yii2 Controller 中两个表中的数据

转载 作者:行者123 更新时间:2023-11-29 15:45:08 27 4
gpt4 key购买 nike

我有日历和通知模型..我正在从日历 Controller 中删除两个模型中的数据..当我尝试使用给定的代码删除时,两条记录都没有发生任何事情..并且我被重定向到通知 Controller ..如何修复此重定向.....\index.php?r=通知/删除&id=1

我尝试过 die();重定向之前的语句,两条记录均已成功删除..

 public function actionDelete($id)
{
// die("deleting");
if(Calendar::find()->where(['id' =>$id])->one()->delete())
{
echo "Calendar Deleted... ...<br>";
if( Notifications::find()->where(['calndar_id' =>$id])->one()->delete())
{
echo "Notification Deleted ....<br>";
$this->redirect(array('index1','message'=>"Calendar & Respective Notification Deleted Successfully"));
}
else
{
$this->redirect(array('index1','message'=>"Calendar Deleted Successfully"));

}

}
}

预期结果是1)两条记录都应该被删除并将重定向到 ..\index.php?r=日历\index

最佳答案

每个redirect()函数必须与return一起使用

public function actionDelete($id)
{
// die("deleting");
if(Calendar::find()->where(['id' =>$id])->one()->delete())
{
echo "Calendar Deleted... ...<br>";
if( Notifications::find()->where(['calndar_id' =>$id])->one()->delete())
{
echo "Notification Deleted ....<br>";
return $this->redirect(array('index1','message'=>"Calendar & Respective Notification Deleted Successfully"));
}
else
{
return $this->redirect(array('index1','message'=>"Calendar Deleted Successfully"));

}

}
}

关于mysql - 如何删除yii2 Controller 中两个表中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57143408/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com