|
PHP复制代码
<?php if ( ! defined('BASEPATH')) exit('不允许直接访问');
class Controller extends Base {
var $_scaffolding = FALSE;
var $_scaff_table = FALSE;
function Controller ()
{
parent ::Base();
$this->_initialize ();
log_message ('debug', "Controller类初始化成功");
}
//初始化控制器
function _initialize ()
{
//载入系统必须的类,方便子类通过$this调用
$classes = array(
'config' => 'Config',
'input' => 'Input',
'benchmark' => 'Benchmark',
'uri' => 'URI',
'output' => 'Output',
'lang' => 'Language',
'router' => 'Router'
);
foreach ($classes as $var => $class)
{
$this->$var =& load_class ($class);
}
//载入loader类,这个类的功能是多个类的装载器,觉得autoloader意义不大,暂时去掉了
if (floor(phpversion()) >= 5)
{
$this->load =& load_class ('Loader');
}
else
{
//因为php4对象是拷贝一份,所以这里和php5做一下兼容
foreach (array_keys(get_object_vars($this)) as $attribute)
{
if (is_object($this->$attribute))
{
$this->load->$attribute =& $this->$attribute;
}
}
}
}
//初始化脚手架
function _scaffolding ()
{
if ($this->_scaffolding === FALSE OR $this->_scaff_table === FALSE)
{
show_404 ('脚手架不能用');
}
$method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3);
require_once(BASEPATH .'scaffolding/Scaffolding'.EXT );
$scaff = new Scaffolding ($this->_scaff_table );
$scaff->$method();
}
}
复制代码 |
|