Example #1
0
 public function __construct()
 {
     global $configs;
     empty($configs->database->host) && show_500('数据库未设置');
     $db = $configs->database->driver;
     $this->db = $db::get_instance($configs->database);
 }
 public function checklog($num = '')
 {
     if (!file_exists(APPPATH . "/views/checklog.php")) {
         show_500();
     }
     $data = $this->input->post();
     $this->load->helper('html');
     $this->load->helper('url');
     $this->load->view('checklog', $data, false);
 }
Example #3
0
 /**
  * 对核心变量赋值
  * @param string $appid
  * @param string $appSecret
  * @param string $token
  * 
  * @return
  */
 public function _init($appid, $appSecret, $encodingAesKey, $token = '')
 {
     if (empty($appid) || empty($appSecret) || empty($encodingAesKey)) {
         show_500('必须保证$appid,$appSecret,$encodingAesKey有值且正确');
     }
     $this->appid = $appid;
     $this->appSecret = $appSecret;
     $this->encodingAesKey = $encodingAesKey;
     empty($token) || ($this->token = $token);
     $this->access_token = $this->access_token();
     return $this;
 }
Example #4
0
 /**
  * 读取缓存
  */
 public function read()
 {
     if ($this->is_allow_cache()) {
         $file = $this->cache_file_path();
         if (file_exists($file)) {
             $html = file_get_contents($file);
             $time = str_replace(']]-->', '', mb_substr($html, -15, NULL, 'UTF-8'));
             is_numeric($time) || show_500('缓存文件格式不正确,无法正确读取');
             if (time() - $time > $this->expires) {
                 $this->compress && extension_loaded('zlib') && ob_start('ob_gzhandler');
                 echo $html;
                 $this->compress && extension_loaded('zlib') && ob_end_flush();
                 exit;
                 // 执行全部结束
             }
         }
     }
 }
Example #5
0
 /**
 * controller的实例化
 *  
 * @param array $cmd
 * $cmd = array('c'=>'index','m'=>'index','d'=>'public','q'=>'a,b,c');
 * @return
 */
 private function cls_instance()
 {
     // 开始缓存
     $cache = new ES_cache($this->cmdq);
     $cache->read();
     $dir = $this->dir_controller . $this->cmdq['d'];
     is_dir($dir) || show_500('控制器文件路径不正确' . $dir);
     $ctl_cls = $this->cmdq['c'];
     require SYSPATH . 'core/controller.php';
     // 拓展基本控制器基类
     $dir_controller_ext = APPPATH . 'core/e_controller.php';
     if (file_exists($dir_controller_ext)) {
         require $dir_controller_ext;
     }
     // 各文件夹自定义控制器基类
     $dir_controller = "{$dir}/e_{$this->cmdq['d']}.php";
     if (file_exists($dir_controller)) {
         require $dir_controller;
     }
     $dir = "{$dir}/{$ctl_cls}.php";
     is_file($dir) || show_500('控制器文件不存在' . $dir);
     require $dir;
     $ctl_cls = ucfirst($ctl_cls);
     // 增加命名空间的支持2015年9月9日23:25:15
     try {
         $reflector = new ReflectionClass(ucfirst($this->cmdq['d']) . '\\' . $ctl_cls);
     } catch (Exception $e) {
         $reflector = new ReflectionClass($ctl_cls);
     }
     $rMethod = null;
     try {
         $rMethod = $reflector->getMethod($this->cmdq['m']);
     } catch (Exception $e) {
         show_500("控制器{$this->cmdq['c']}方法{$this->cmdq['m']}不存在");
     }
     $this->disable_method($rMethod);
     $rMethod->isConstructor() && show_500('用默认函数的类需要有构造函数__construct()');
     $args = array();
     if (!empty($this->cmdq['q'])) {
         // 如果使用汇总压缩css,js,则不能用,分割参数
         $args = $this->cmdq['c'] == 'min' ? array($this->cmdq['q']) : explode(',', $this->cmdq['q']);
     }
     $cls = $reflector->newInstance();
     is_subclass_of($cls, 'ES_controller') || show_500('控制器必须是ES_controller的子类');
     $rMethod->invokeArgs($cls, $args);
     $cls->closeDB();
     // 关闭数据库
     $html = $cls->output->display(1);
     // 输出
     $cache->save($html);
     $flag = $cls->load->config('config', 'compress_outpage');
     $flag && $cls->output->length() > 1024 && extension_loaded('zlib') && ob_start('ob_gzhandler');
     echo $html;
     $flag && $cls->output->length() > 1024 && extension_loaded('zlib') && ob_end_flush();
 }
Example #6
0
 /**
 * 载入视图
 * @param string $dir html/php视图的文件路径,application/views下的什么位置
 * @param array $data
 * 
 * @return void
 */
 public function view($dir, $data = array())
 {
     !empty($data) && is_array($data) && extract($data);
     $file = APPPATH . $this->dir_view . 'html/' . $dir . '.php';
     is_file($file) || show_500('view文件不存在,' . $file);
     ob_start();
     include $file;
     $output = ob_get_contents();
     @ob_end_clean();
     $controller = ES_controller::get_instance();
     $controller->output->append_output($output);
 }