Fatal error: Uncaught exception 'Exception' with message '找不到控制器,请问如何解决 谢谢
Fatal error: Uncaught exception 'Exception' with message '找不到控制器' in E:\phpstudy\PHPTutorial\WWW\my\core\my.php:34 Stack trace: #0 E:\phpstudy\PHPTutorial\WWW\my\index.php(37): core\my::run() #1 {main} thrown in E:\phpstudy\PHPTutorial\WWW\my\core\my.php on line 34
<?php
namespace core;
/*
命名空间
类
方法
*/
class my {
public static $classMap = array();
public $assign;
// run方法调用路由类
static public function run(){
//p( 'ok' );
$route = new \core\lib\route();
//p($route);
$ctrlClass = $route->ctrl;
$action = $route->action;
$ctrlfile=APP.'/ctrl/'.$ctrlClass.'Ctrl.php';
// \app\ctrl\indexCtrl
$cltrlClass='\\'.MODULE.'\ctrl\\'.$ctrlClass.'Ctrl';
//p($ctrlClass); // 应该index,而不是index.php
//p($action); // 它是index,自己返过来的时候结果是正确的
//p($ctrlfile);
//p($cltrlClass);
//exit();
if(is_file($ctrlfile)){
include $ctrlfile;
$ctrl = new $cltrlClass();
$ctrl->index(); // 不是$index()
}else{
throw new \Exception('找不到控制器'.$ctrlClass);
}
}
static public function load( $class ) {
// 自动加载类库
// new \core\route();
// $class='\core\route';
// MY.'\core\route.php';
//p( $class );
//p(MY.$class.'.php');
//p( MY .'\\' . $class . '.php' );
//print_r( $class );
// 避免重复加载:老师这一步有问题
if ( isset( $classMap[ $class ] ) ) {
return true;
} else {
$class = str_replace( '\\', '/', $class );
$file = MY . '/' . $class . '.php';
if ( is_file( $file ) ) {
include $file;
self::$classMap[ $class ] = $class;
} else {
return false;
}
}
}
public function assign($name,$value){
$this->assign[$name]=$value;
}
public function display($file){
$file=APP.'/views/'.$file;
if(is_file($file)){
//p($this->assign);//exit;
extract($this->assign);
include $file;
}
}
}
?>