data[$name]); } public function __set($name, $value = null) { $this->data[$name] = $value; } public function __get($name) { return isset($this->data[$name]) ? $this->data[$name] : null; } /** * 设置模板路径 * @param $path * @return $this */ public function setPath($path) { if ($path) { $this->path = rtrim($path, '/') . DIRECTORY_SEPARATOR; } return $this; } /** * 设置模板后缀 * @param $suffix * @return $this */ public function setSuffix($suffix) { if ($suffix) { $this->suffix = $suffix; } return $this; } /** * 设置模板名称 * @param $tpl * @return $this */ public function setTpl($tpl) { if ($tpl) { $this->tpl = $tpl; } return $this; } /** * 变量赋值, 可以单独赋值,也可以批量赋值 * @param $name * @param null $value * @return $this */ public function assign($name, $value = null) { if (is_array($name)) { foreach ($name as $k => $v) { $this->data[$k] = $v; } } else { $this->data[$name] = $value; } return $this; } /** * 获取全部数据 * @return array */ public function getData() { return $this->data; } /** * 载入其他模板 * @param $tpl * @return null */ public function load($tpl) { $tpl = $this->path . $tpl . $this->suffix; if (is_readable($tpl)) { include($tpl); } else { return null; } } /** * 渲染页面 * @param bool $isReturn * @param string $layout * @return string */ public function render($isReturn = false, $layout = '') { $filename = $this->path . $this->tpl . $this->suffix; // 判断模板是否存在 if (!is_readable($filename)) { Logger::error($filename, 'template.not_found'); return ''; } // 判断layout是否存在 if ($layout && is_readable($this->path . $layout . $this->suffix)) { $filename = $this->path . $layout . $this->suffix; } if ($isReturn == false) { include($filename); } else { ob_start(); include($filename); $content = ob_get_contents(); ob_end_clean(); return $content; } } /** * 输出ajax信息 * @param bool $result * @param null $code * @param null $msg * @param null $data */ public function output($result = true, $code = null, $msg = null, $data = null) { if ($result instanceof Exception) { $code = $result->getCode(); $msg = $result->getMessage(); $data = $result->__toString(); $result = false; } if ($result AND !is_bool($result) AND is_null($data)) { $data = $result; } $result = (bool)$result; $code = (int)$code; $msg = (!empty($msg)) ? $msg : ''; $data = (!empty($data)) ? $data : ''; $data = array( 'result' => $result, 'code' => $code, 'msg' => $msg, 'data' => $data, ); header('Content-type: application/json'); echo json_encode($data); } /** * 获取同域名下的其他子域名 * @param $domain * @return string */ protected function getDomainHost($domain) { $domainHost = $_SERVER['HTTP_HOST']; $domainHost = $domainHost."/".$domain; return $domainHost; } protected function getPager($pager){ // if($pager['total_page'] == 0 || $pager['total_page'] <= $pager['page_size']){ // return ''; // } $current_start = ($pager['current_page']-1)*$pager['page_size']+1; $current_end = $pager['current_page']*$pager['page_size'] < $pager['total_count'] ? $pager['current_page']*$pager['page_size']:$pager['total_count']; $html = '