CakePHP:我如何捕获mkdir错误


CakePHP: How can I catch mkdir error?

我目前使用以下代码在CakePHP 1.3.10(使用PHP 5.2.17)当mkdir返回false:

CakeLog::write('error', "An error occurred while creating the '"$target_dir'" directory.");

我还想捕获准确的错误消息,例如:

Warning (2): mkdir() [function.mkdir]: File exists
然后我可以在日志中包含该错误消息。我怎么能做到这一点与CakePHP?我试过使用error_get_last函数,但它只是说:
Non-static method Configure::getInstance() should not be called statically, assuming $this from incompatible context

您实际上是在尝试捕捉一个警告。这里有一个对应的方法

函数file_exists()也检查目录是否存在。你可以试试