致命错误:未被捕获的错误:类'MVC \library \ notfoundexception' - 自动加载器 [英] Fatal error: uncaught error: class 'MVC\library\notfoundexception' - autoloader
本文介绍了致命错误:未被捕获的错误:类'MVC \library \ notfoundexception' - 自动加载器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想我的自动加载器可能无法正常工作。
我认为最安全的做法是向我展示我的目录
目录布局
和这是我的自动装弹机
I think I might have a problem with my autoloader not working correctly.
I think the safest thing to do is show you my directories
Directory Layout
And here is my autoloader
<?php
// simple autoloader
spl_autoload_register(function ($className) {
if (substr($className, 0, 4) !== 'Mvc\\') { //' // [EDIT: Format fix]
// not our business
return;
}
$fileName = __DIR__.'/'.str_replace('\\', DIRECTORY_SEPARATOR, substr($className, 4)).'.php'; //' // [EDIT: Format fix]
if (file_exists($fileName)) {
include $fileName;
}
});
// get the requested url
$url = (isset($_GET['_url']) ? $_GET['_url'] : '');
$urlParts = explode('/', $url);
// build the controller class
$controllerName = (isset($urlParts[0]) && $urlParts[0] ? $urlParts[0] : 'index');
$controllerClassName = '\\Mvc\\Controller\\'.ucfirst($controllerName).'Controller'; //' // [EDIT: Format fix]
// build the action method
$actionName = (isset($urlParts[1]) && $urlParts[1] ? $urlParts[1] : 'index');
$actionMethodName = $actionName.'Action';
try {
if (!class_exists($controllerClassName)) {
throw new \Mvc\Library\NotFoundException();
}
$controller = new $controllerClassName();
if (!$controller instanceof \Mvc\Controller\Controller || !method_exists($controller, $actionMethodName)) {
throw new \Mvc\Library\NotFoundException();
}
$view = new \Mvc\Library\View(__DIR__.DIRECTORY_SEPARATOR.'views', $controllerName, $actionName);
$controller->setView($view);
$controller->$actionMethodName();
$view->render();
} catch (\Mvc\Library\NotFoundException $e) {
http_response_code(404);
echo 'Page not found: '.$controllerClassName.'::'.$actionMethodName;
} catch (\Exception $e) {
http_response_code(500);
echo 'Exception: '.$e->getMessage().'<br><pre>'.$e->getTraceAsSt . ring().
第30行引发错误这将是:
The error is thrown on line 30 which would be:
throw new \Mvc\Library\NotFoundException();
它还说:
It also says :
Stack trace: #0 {main}
我在这里缺少什么?
提前谢谢。
我尝试过的事情:
我试图让那些被认为与某些事情有关的导弹转移我的xxamp配置。
What am I missing here?
Thank you in advance.
What I have tried:
I have tried moving the direcotires around thinking that is has something to do with my xxamp configuration.
推荐答案
className){
if (substr(
className) { if (substr(
)
className,0,4)!== ' Mvc \\'){ // '//
// 不是我们的业务
return ;
}
className, 0, 4) !== 'Mvc\\') { //' // // not our business return; }
fileName = __DIR __。' /' .str_replace(' \\',DIRECTORY_SEPARATOR,substr(
fileName = __DIR__.'/'.str_replace('\\', DIRECTORY_SEPARATOR, substr(
这篇关于致命错误:未被捕获的错误:类'MVC \library \ notfoundexception' - 自动加载器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文