开发者

Handling unreadable/not found files in MVC (PHP)

I'm still writing my simple MVC for learning and eventually make a framework for my applications and now I'm writing the routing class and have faced dilemma. Since this community is big, I wanted to hear different opinions before continue. At some point entered URL might not match any controller or there might be a controller with unreadable file. Now I'm faced with dilemma on how do I notify user of the situation.

First option that I see is throwing an exception. This is easy option but catching exceptions might be a problem and it is not centralized.

Another is calling error controller populating a me开发者_JS百科ssage error or fixed error. There might be other options and I would like to hear from you buddies.


I went with either including the file or redirecting to error page

 if (file_exists($file_path) && is_readable($file_path)) {
                //the file is valid, include it
                require $file_path;
 }else{
    redirect_to_error_page(404);
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜