1

I want to delete a directory associated to a record but not if the directory is not empty although I know by default we cannot delete a non empty dir by rmdir() and it will flash an error. But this is a compiler error and I want to print a error within the application telling the user why the dir can not be deleted. basically what I'm looking for is something like this:-

 public function actionDelete($id)
 if(some condition here to check the dir is empty)
 {
        rmdir("path of the dir")
 }else {
       a flash msg here saying directory is not empty 
 }

provided that using yii2 framework of php.

Cœur
  • 37,241
  • 25
  • 195
  • 267
rahul s negi
  • 139
  • 14
  • 1
    Here is an answer how to catch E_WARNING http://stackoverflow.com/questions/1241728/can-i-try-catch-a-warning – SiZE Feb 09 '16 at 07:00

1 Answers1

0

You can use setFlash() method for Flash Message.

For example,

public function actionDelete($id)
{
  try
  {
     rmdir("path of the dir")
  }
  catch(Exception $e) 
  {
     Yii::$app->session->setFlash('error', 'Custom error message or catched exception.')); 
  }
}
Insane Skull
  • 9,220
  • 9
  • 44
  • 63