Answer the question
In order to leave comments, you need to log in
How to delete a file physically in Yii2 by linked table in a loop?
standard delete function
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['advbyuser']);
}
Answer the question
In order to leave comments, you need to log in
Good afternoon.
Is there a foreign key relationship?
If it is, then when the record is deleted, the records from the image table will be deleted.
And the directory can be deleted like this:
public function actionDelete($id)
{
if($this->findModel($id)->delete()){
FileHelper::removeDirectory($path_to_dir);
}
return $this->redirect(['advbyuser']);
}
public function beforeDelete()
{
if(!parent::beforeDelete()){
return false;
}
$path = 'path_to_dir';
FileHelper::removeDirectory($path);
return true;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question