<?php
|
|
/**
|
* 后台通用控制器 加了rbac
|
* Class AdminCommonController
|
*/
|
class System_Controller_Base extends Yaf_Controller_Abstract{
|
|
protected $redis;
|
|
private $request;
|
/**
|
* @var string 信息提示模板
|
*/
|
public $defaultMsgTemplate = 'error/showmsg.phtml';
|
/**
|
* @var string 布局文件
|
*/
|
public $layout;
|
/**
|
* 栏目模块
|
* @var [type]
|
*/
|
public $modules;
|
|
public $route;
|
|
public $site_url;
|
|
public $config = array();
|
|
public function __set($name, $value){
|
$this->$name = $value;
|
}
|
|
public function __get($name){
|
if(isset($this->$name)){
|
return $this->$name;
|
}else{
|
return NULL;
|
}
|
}
|
|
public function init()
|
{
|
$this->config['site_url'] = Yaf_Registry::get('var');
|
$this->request = $this->getRequest();
|
//do not call render for ajax request
|
if ($this->isAjax()) {
|
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
|
}
|
$this->route = $this->getRoute();
|
//初始化redis
|
$this->redis = System_Service_Locator::getInstance()->get('redis');
|
//是否渲染模板
|
if(!empty($this->layout)){
|
//根据角色权限访问
|
//$this->modules = $this->modules_service->getModuleListByRoleId();
|
$this->setLayout($this->layout);
|
}
|
|
//将当前路由值传入模板
|
$this->getView()->assign('route', $this->route);
|
}
|
|
/**
|
* 设置布局
|
* @param string $layout 布局文件
|
*/
|
private function setLayout($layout)
|
{
|
$this->getResPonse()->modules = $this->redis->get('modules');
|
$this->getResPonse()->route = $this->route;
|
$this->getResPonse()->layout = function($content, $modules, $route) use ($layout){
|
//$content子视图的内容
|
return $this->getView()->render($layout, ['content'=>$content, 'modules' => $modules, 'route' => $route]);
|
};
|
}
|
|
/**
|
* 设置布局
|
* @param string $layout 布局文件
|
*/
|
public function _setLayout($layout)
|
{
|
$this->layout = $layout;
|
}
|
|
/**
|
* 获取当前路由
|
* @return [type] [description]
|
*/
|
public function getRoute(){
|
return array('module' => strtolower($this->getRequest()->module), 'controller' => strtolower($this->getRequest()->controller), 'action' => strtolower($this->getRequest()->action));
|
}
|
|
/**
|
* 获取post数值
|
* @param [type] $name [description]
|
* @param string $default_value [description]
|
* @return [type] [description]
|
*/
|
public function post($name, $default_value = ""){
|
return $this->getRequest()->getPost($name, $default_value);
|
}
|
|
/**
|
* 获取GET数值
|
* @param [type] $name [description]
|
* @param string $default_value [description]
|
* @return [type] [description]
|
*/
|
public function get($name, $default_value = ""){
|
return $this->getRequest()->getQuery($name, $default_value);
|
}
|
|
/**
|
* 判断是否是ajax请求
|
* @return boolean [description]
|
*/
|
public function isAjax(){
|
return $this->getRequest()->isXmlHttpRequest();
|
}
|
|
|
}
|