|
发表于 2012-10-11 15:50:35
|
显示全部楼层
我直接改写ci的控制器/core/contrellor
PHP复制代码
class CI_Controller {
private static $instance;
/**
* Constructor
*/
public function __construct ()
{
self::$instance =& $this;
// Assign all the class objects that were instantiated by the
// bootstrap file (CodeIgniter.php) to local class variables
// so that CI can run as one big super object.
foreach (is_loaded () as $var => $class)
{
$this->$var =& load_class ($class);
}
$this->load =& load_class ('Loader', 'core');
$this->load->initialize();
log_message ('debug', "Controller Class Initialized");
}
public static function &get_instance ()
{
return self::$instance;
}
/**
* 扩展ci处理视图功能,提供类似嵌入式布局,SEO优化
* $data array要传递到视图的数据
* $template string内容模板
* $seokey string使用的seo数据在配置文件里的键名索引,默认不使用
* $rtemplate array替换默认模板,可选索引参数,header,footer
*/
public function render ($template, $data = array(), $seokey = null, $rtemplate = array())
{
// layout
$layout = array(
'header' => isset($rtemplate['header']) ? $rtemplate['header'] : 'common/header',
'content' => $template,
'footer' => isset($rtemplate['footer']) ? $rtemplate['footer'] : 'common/footer',
);
// seo
// _title, _keywords, _description为保留关键字
$seo_data = array(
'_title' => '',
'_keywords' => '',
'_description' => ''
);
// need seo
if($seokey != null) {
$this->config->load('xconfig/seo', true, true);
$seo_data = $this->config->item($seokey, 'xconfig/seo');
}
// merge the data
$data = array_merge($data, $seo_data);
// load view
foreach($layout as $key => $value) {
$this->load->view($value, $data);
}
}
}
复制代码 |
|