|
PHP复制代码 /**
*加载控制器
* $controller 控制器的路径, 支持数组和string
* $method 方法, 方法和控制器一一对应, 支持array和string
* $name 别名, name值得标准为controller
*/
public function controller ($controller, $method = 'index', $name = '')
{
if ($controller == '')
{
return;
}
if (is_array($controller) AND is_array($method) AND !empty($method))
{
foreach ($controller as $k=> $control)
{
$this ->controller($controller, $method[$k]);
}
return;
}
if (is_array($controller) AND is_string($method))
{
foreach ($controller as $control)
{
$this ->controller($controller, $method);
}
return;
}
$x = explode('/', $controller);
if ($name == '')
{
$name = $x[2];
}
if (in_array($name, $this ->_ci_controllers ))
{
return;
}
$CI = &get_instance ();
if (isset($CI->$name))
{
show_error ('控制器名称已经被占用了');
}
if (!is_dir(APPPATH . 'controllers/' . dirname($controller)) OR !file_exists(APPPATH .'controllers/'.strtolower($controller).'.php'))
{
show_error ('加载的控制器不存在,无法加载');
}
if (($subclass = $CI ->config ->item('subclass_prefix')) == '' AND file_exists(APPPATH . 'core/' . $subclass . '_Controller.php'))
{
include APPPATH . 'core/' . $subclass . '_Controller.php';
}
include APPPATH . 'controllers/' . $controller . '.php';
if (!class_exists( $control = ucfirst($x[2])))
{
show_error ('加载的类不存在');
}
$CI->$name = new $control();
$this->_ci_controllers [] = $name;
return true;
}
复制代码
|
评分
-
查看全部评分
|