├── .gitignore ├── .htaccess ├── README ├── application ├── baseController.php ├── baseModel.php ├── load.php ├── registry.php ├── request.php └── router.php ├── controllers ├── errorController.php ├── indexController.php └── testController.php ├── index.php ├── lib └── css │ └── style.css ├── models └── postsModel.php └── views └── indexView.php /.gitignore: -------------------------------------------------------------------------------- 1 | *.php~ 2 | -------------------------------------------------------------------------------- /.htaccess: -------------------------------------------------------------------------------- 1 | RewriteEngine On 2 | 3 | RewriteCond %{REQUEST_FILENAME} !-f 4 | 5 | RewriteRule ^(.+)$ /index.php/$1 6 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jontyy/PHP-Basic-MVC-Framework/4e4011142092bf89aef1ec6180ca4d7fd8b31853/README -------------------------------------------------------------------------------- /application/baseController.php: -------------------------------------------------------------------------------- 1 | _registry = Registry::getInstance(); 10 | $this->load = new Load; 11 | } 12 | abstract public function index(); 13 | 14 | final public function __get($key){ 15 | if($return = $this->_registry->$key){ 16 | return $return; 17 | } 18 | return false; 19 | } 20 | } 21 | ?> 22 | -------------------------------------------------------------------------------- /application/baseModel.php: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /application/load.php: -------------------------------------------------------------------------------- 1 | $name = new $model; 27 | return true; 28 | } 29 | } 30 | throw new Exception('Model issues.'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /application/registry.php: -------------------------------------------------------------------------------- 1 | _storage[$key] = $val; 21 | } 22 | 23 | public function __get($key){ 24 | if(isset($this->_storage[$key])){ 25 | return $this->_storage[$key]; 26 | } 27 | return false; 28 | } 29 | } 30 | ?> 31 | -------------------------------------------------------------------------------- /application/request.php: -------------------------------------------------------------------------------- 1 | _controller = ($c = array_shift($parts))? $c: 'index'; 15 | $this->_method = ($c = array_shift($parts))? $c: 'index'; 16 | $this->_args = (isset($parts[0])) ? $parts : array(); 17 | } 18 | 19 | public function getController(){ 20 | return $this->_controller; 21 | } 22 | public function getMethod(){ 23 | return $this->_method; 24 | } 25 | public function getArgs(){ 26 | return $this->_args; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /application/router.php: -------------------------------------------------------------------------------- 1 | getController().'Controller'; 8 | $method = $request->getMethod(); 9 | $args = $request->getArgs(); 10 | 11 | $controllerFile = SITE_PATH.'controllers/'.$controller.'.php'; 12 | 13 | if(is_readable($controllerFile)){ 14 | require_once $controllerFile; 15 | 16 | $controller = new $controller; 17 | $method = (is_callable(array($controller,$method))) ? $method : 'index'; 18 | 19 | if(!empty($args)){ 20 | call_user_func_array(array($controller,$method),$args); 21 | }else{ 22 | call_user_func(array($controller,$method)); 23 | } 24 | return; 25 | } 26 | 27 | throw new Exception('404 - '.$request->getController().' not found'); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /controllers/errorController.php: -------------------------------------------------------------------------------- 1 | '.print_r($message,1).''; 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /controllers/indexController.php: -------------------------------------------------------------------------------- 1 | load->model('posts'); 10 | 11 | $vars['title'] = 'Dynamic title'; 12 | $vars['posts'] = $this->posts->getEntries(); 13 | $this->load->view('index',$vars); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /controllers/testController.php: -------------------------------------------------------------------------------- 1 | '.print_r(__METHOD__,1).''; 7 | 8 | } 9 | 10 | 11 | public function peas(){ 12 | echo '
'.print_r(__METHOD__,1).''; 13 | echo '
'.print_r(func_get_args(),1).''; 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | error($e->getMessage()); 23 | } 24 | -------------------------------------------------------------------------------- /lib/css/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jontyy/PHP-Basic-MVC-Framework/4e4011142092bf89aef1ec6180ca4d7fd8b31853/lib/css/style.css -------------------------------------------------------------------------------- /models/postsModel.php: -------------------------------------------------------------------------------- 1 | 'hello world'); 8 | $return[1] = array('title'=>'hello universe'); 9 | 10 | return $return; 11 | } 12 | } 13 | ?> 14 | -------------------------------------------------------------------------------- /views/indexView.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |