Home  >  Q&A  >  body text

PHP automatic loading error cannot find the reason, please help me

QQ浏览器截图20200307005945.png<?phpnamespace framework\core;
class Framework{ //Initialize in the constructor method public function __construct() { $this->autoload(); $this->initMCA(); $this->dispatch(); } //Register for automatic loading public function autoload() {           //Note: If the parameter of a function is a callback function, just write the name of the function directly                                                                                          Object method spl_autoload_register(array($this,"autoloader")); //Auto-loading and execution function public function autoloader($className) { echo 'We need:'.$className.'<br>'; / /Make a special case for third-party classes if($className=='Smarty'){ require_once './framework/vendor/smarty/Smarty.class.php'; return; Namespace classes, separated $arr = explode('\\', $className); //2. Determine the root directory to load based on the first element if($arr[0] == 'framework'){ $basic_path='./'; ; if(substr($arr[count($arr)-1], 0,2)=='I_'){                                                                                                                                                $fix = ' .class.php'; }$class_file = $basic_path.$sub_path.$fix; //5. Loading the class //If it is not defined according to the rules of our namespace, it means it is not a class we need to load, so there is no need to load it if(file_exists($class_file)) {                                                                                                                                                                                                 require_once $class_file; $m = isset($_GET['m'])?$_GET['m']:'home'; define('MODULE', $m); //Which controller to access $c = isset($_GET[ 'c'])?$_GET['c']:'Index'; define('CONTROLLER', $c); //Which operation of the controller is accessed? $a = isset($_GET['a'])? $_GET['a']:'indexAction'; define('ACTION', $a); } //Instantiate the object and call the method public function dispatch() { $controller_name = MODULE.'\controller\\'.CONTROLLER .'Controller';                                                                                                                                                                                                                                                                 First, load the controller class, then instantiate the            $controller #

有病呻吟有病呻吟1709 days ago922

reply all(1)I'll reply

  • justin

    justin2020-03-11 08:40:12

    Re-download smarty and check if there is a sysplugins folder in the smart in your project and if there is no plugins folder, then take the exam.

    reply
    0
  • Cancelreply