---
layout:     readme
title:      "加载控制器"
subtitle:   "Load controller"
date:       2019-01-11 20:00:00
author:     "吴庆宝"
tags:
    - phpms框架
---

CORE.'/phpmsframe.php';

```
$route = new \core\lib\route();
$ctrlClass = $route->ctrl;
$action = $route->action;		
$ctrlfile = APP.'/ctrl/'.$ctrlClass.'Ctrl.php';
$ctrlClass = '\\'.MODULE.'\ctrl\\'.$ctrlClass.'Ctrl';
if(is_file($ctrlfile)){			
	include $ctrlfile;			
	$ctrl = new $ctrlClass();
	$ctrl->$action();					
}
```

include CORE.'/lib/route.php';

```
<?php

namespace core\lib;

use \core\lib\conf;

class route
{
	public $ctrl;

	public $action;

	public function __construct(){
		if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/'){
			$path = $_SERVER['REQUEST_URI'];
			$patharr = explode('/', trim($path,'/')) ;
			if(isset($patharr[0])){
				$this->ctrl = $patharr[0];
			}
			unset($patharr[0]);
			if(isset($patharr[1])){
				$this->action = $patharr[1];
			}else{
				$this->action = conf::get('ACTION','route');
			}
			unset($patharr[1]);
			$count = count($patharr)+2;
			$i = 2;
			while ( $i < $count) {
				if(isset($patharr[$i+1])){
					$_GET[$patharr[$i]] = $patharr[$i+1];
					$i = $i+2;
				}				
			}			
		}else{
			$this->ctrl = conf::get('CTRL','route');
			$this->action = conf::get('ACTION','route');
		}
		
	}
}
```
