Php 如何在删除非空目录之前刷新错误消息
我想删除与记录关联的目录,但如果该目录不是空的,则不想删除,尽管我知道默认情况下,我们不能通过Php 如何在删除非空目录之前刷新错误消息,php,yii2,yii2-basic-app,Php,Yii2,Yii2 Basic App,我想删除与记录关联的目录,但如果该目录不是空的,则不想删除,尽管我知道默认情况下,我们不能通过rmdir()删除非空目录,并且它将闪烁一个错误。但是这是一个编译器错误,我想在应用程序中打印一个错误,告诉用户为什么不能删除dir。基本上我要找的是这样的东西:- public function actionDelete($id) if(some condition here to check the dir is empty) { rmdir("path of the dir"
rmdir()
删除非空目录,并且它将闪烁一个错误。但是这是一个编译器错误,我想在应用程序中打印一个错误,告诉用户为什么不能删除dir。基本上我要找的是这样的东西:-
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
}
前提是使用php的yii2
框架。您可以对Flash消息使用方法
比如说,
public function actionDelete($id)
{
try
{
rmdir("path of the dir")
}
catch(Exception $e)
{
Yii::$app->session->setFlash('error', 'Custom error message or catched exception.'));
}
}
您可以使用此方法来发送Flash消息
比如说,
public function actionDelete($id)
{
try
{
rmdir("path of the dir")
}
catch(Exception $e)
{
Yii::$app->session->setFlash('error', 'Custom error message or catched exception.'));
}
}
这是一个如何捕捉E_警告的答案这是一个如何捕捉E_警告的答案它仍然显示编译器错误而不是flash错误它仍然显示编译器错误而不是flash错误