Phpmvc
I would like to try to write a simple MVC framework, the results of the automatic loading is stuck, to seek the expert guidance
This is the directory structure
The code is as follows
Entry file index.php
Define (' BASEDIR ', __dir__);
Require BASEDIR. ' \autoload.php ';
Spl_autoload_register (' controllers\loader::autoload ');
$c = Strtolower ($_get[' C '); Controller name
$a = Strtolower ($_get[' a '); Method name
$controller = ' controllers\index\ '. $c. ' Controller '; This is the place where I want to go directly to new, without having to add a namespace in front of you and not know how to implement it.
$controller = $c. ' Controller ';
$obj = new $controller ();
$obj $a ();
Controller commonController.class.php:
namespace Controllers\common;
Class Commoncontroller {
/**
- @param string $templets
- @param array $var */public function display ($templets, $var) {define (' BASEDIR ', __dir__); Ob_clean (); Ob_start (); extract ($var); $templets = Str_replace ('/', ' \ ', $templets); $tmp _file = BASEDIR. ' \views\ '. $templets. HTML '; include_once $tmp _file;echo ob_get_contents ();}}
Controller indexController.class.php:
namespace Controllers\index;
Use Controllers\common\commoncontroller;
Class Indexcontroller extends commoncontroller{
Public Function index () {
$this->display (' Index/index ', [' Test ' = ' success ']);
}
}
Auto-load Class autoload.php:
namespace controllers;
Class loader{
static function AutoLoad ($className) {
$class = BASEDIR. ' \ '. $className. ' Class.php ';
$class = str_replace (' \ ', '/', $class);
if (file_exists ($class)) {
Include_once $class;
}
}
}
I would like to load the class directly in the portal file without needing to add a namespace in front of it, what to do, ask the big God for guidance under