yii2:使用单个控制器操作删除两个表中的值?
yii2: delete values in two tables using single controller action?
我有两个 tables table1 和 table2 并且我试图删除这两个 table.I 中的行 [=16] 具有相同的值=] 但 id 不同所以我这样试过,
我的控制器,
public function actionDelete($id)
{
$this->findModel($id);
$select = Employee::find()
->select('Name')
->where(['Id' => $id])
->all();
$deluser=Employee::find()->where(['Id' => $id])->one()->delete() AND User::find()->where(['Name' =>$select])->one();
$deluser->delete();
return $this->redirect(['index','select'=>$select]);
}
请任何人帮助我
提前致谢
员工class是对象。
试试这个:
public function actionDelete($id)
{
$this->findModel($id);
$select = Employee::find()
->select('Name')
->where(['Id' => $id])
->all();
Employee::find()->where(['id' => $id])->one()->delete();
User::find()->where(['id' =>$id])->one()->delete();
return $this->redirect(['index','select'=>$select]);
}
我有两个 tables table1 和 table2 并且我试图删除这两个 table.I 中的行 [=16] 具有相同的值=] 但 id 不同所以我这样试过, 我的控制器,
public function actionDelete($id)
{
$this->findModel($id);
$select = Employee::find()
->select('Name')
->where(['Id' => $id])
->all();
$deluser=Employee::find()->where(['Id' => $id])->one()->delete() AND User::find()->where(['Name' =>$select])->one();
$deluser->delete();
return $this->redirect(['index','select'=>$select]);
}
请任何人帮助我 提前致谢
员工class是对象。
试试这个:
public function actionDelete($id)
{
$this->findModel($id);
$select = Employee::find()
->select('Name')
->where(['Id' => $id])
->all();
Employee::find()->where(['id' => $id])->one()->delete();
User::find()->where(['id' =>$id])->one()->delete();
return $this->redirect(['index','select'=>$select]);
}