📄 正在查看:twcms/kongphp/base/control.class.php
1<?php
2/**
3 * Copyright (C) 2013-2014 www.kongphp.com All rights reserved.
4 * Licensed http://www.gnu.org/licenses/lgpl.html
5 * Author: wuzhaohuan <kongphp@gmail.com>
6 */
7
8class control{
9 public function __get($var) {
10 if($var == 'view') {
11 return $this->view = new view();
12 }elseif($var == 'db') {
13 $db = 'db_'.$_ENV['_config']['db']['type'];
14 return $this->db = new $db($_ENV['_config']['db']); // 给开发者调试时使用,不建议在控制器中操作 DB
15 }else{
16 return $this->$var = core::model($var);
17 }
18 }
19
20 public function assign($k, &$v) {
21 $this->view->assign($k, $v);
22 }
23
24 public function assign_value($k, $v) {
25 $this->view->assign_value($k, $v);
26 }
27
28 public function display($filename = null) {
29 $this->view->display($filename);
30 }
31
32 public function message($status, $message, $jumpurl = '', $delay = 2) {
33 if(R('ajax')) {
34 echo json_encode(array('kong_status'=>$status, 'message'=>$message, 'jumpurl'=>$jumpurl, 'delay'=>$delay));
35 }else{
36 if(empty($jumpurl)) {
37 $jumpurl = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
38 }
39 include KONG_PATH.'tpl/sys_message.php';
40 }
41 exit;
42 }
43
44 public function __call($method, $args) {
45 // DEBUG关闭时,为防止泄漏敏感信息,用404错误代替
46 if(DEBUG) {
47 throw new Exception('控制器没有找到:'.get_class($this).'->'.$method.'('.(empty($args) ? '' : var_export($args, 1)).')');
48 }else{
49 core::error404();
50 }
51 }
52}
53