<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Layout {
var $obj;
/** 默认layout页名称 */
var $layout = "main";
var $layout_data;
function Layout($params = array()) {
$this->obj =& get_instance();
if (count($params) > 0) {
$this->init($params);
}
// 为了方便layout页的管理,所以在views文件夹下建了个layouts文件夹
$this->layout = "layouts/" . $this->layout;
}
function init($params = array()) {
if (count($params) > 0) {
foreach ($params as $key => $val) {
$this->$key = $val;
}
}
}
/**
* 渲染页面
* @param $view
string 主体视图名称
* @param $data
array() 主体视图所需数据数组
* @param $is_return boolean 是否返回渲染页面的字符串表现形式
* @return string/void
*/
function view($view, $data = null,$is_return = false) {
$this->layout_data['layout_body'] = $this->obj->load->view($view, $data, true);
if($is_return) {
$output = $this->obj->load->view($this->layout, $this->layout_data, true);
return $output;
}
else {
$this->obj->load->view($this->layout, $this->layout_data, false);
}
}
}
?>