/** * 保存日志 * @return bool */ public function save() { $content_arr = $this->getSaveContent(); if (empty($content_arr)) { return false; } $suffix = '.log'; $path = H::app()->log_path . '/' . date('Y/m/d'); if ($this->makeDir($path)) { foreach ($content_arr as $file_name => $log_arr) { $file_arr = glob($path . '/' . $file_name . '*.log'); $num = count($file_arr); if ($num > 0) { $file_path = $file_arr[$num - 1]; $file_size = filesize($file_path) / 1024; if ($file_size >= $this->_max_size) { $num++; } } else { $num++; } $file_path = $path . '/' . $file_name . '_' . $num . $suffix; //写入方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建 $handle = fopen($file_path, 'a'); if ($handle) { foreach ($log_arr as $content) { fwrite($handle, $content); } fclose($handle); } } } $this->_log_arr = array(); return true; }
<?php //项目目录 defined('H_APP_PATH') or define('H_APP_PATH', dirname(__FILE__)); //入口文件 defined('H_APP_ENTRY_FILE') or define('H_APP_ENTRY_FILE', basename(__FILE__)); //引用H+ include H_APP_PATH . '/H+/H.php'; H::app()->run();
/** * 生成url * @param string $str 生成字符串 * /test test控制器 默认方法 * /test/show test控制器 show方法 * test 当前控制器 test方法 * test/show test控制器 show方法 * @param array $param 需要生成URL的参数数组 * @return string */ public function genurl($str, $param = array()) { $controller = $this->controller; $char = substr($str, 0, 1); if ($char == '/') { $action = substr($str, 1); } else { $arr = explode('/', $str); if (count($arr) > 1) { $controller = isset($arr[0]) ? $arr[0] : ''; $action = isset($arr[1]) ? $arr[1] : ''; } else { $action = isset($arr[0]) ? $arr[0] : ''; } } $param_arr = array(); //参数数组 //是否为参数路由类型 if (H::app()->getConfig('is_param_route')) { $param_route_key = H::app()->getConfig('param_route_key'); $param_route_separator = H::app()->getConfig('param_route_separator'); $url = H::app()->base_url . '/' . H_APP_ENTRY_FILE; $param_arr[] = $param_route_key . '=' . $controller . $param_route_separator . $action; } else { $url = H::app()->base_url . '/' . $controller . '/' . $action; } //处理参数 foreach ($param as $key => $val) { $param_arr[] = $key . '=' . $val; } if (!empty($param_arr)) { $url .= '?' . implode('&', $param_arr); } return $url; }
/** * 回复文本消息 * @param string $msg */ public function replyMsgText($msg) { $fromUserName = $this->_xml_obj->FromUserName; $toUserName = $this->_xml_obj->ToUserName; $textTpl = "<xml>\n <ToUserName><![CDATA[%s]]></ToUserName>\n <FromUserName><![CDATA[%s]]></FromUserName>\n <CreateTime>%s</CreateTime>\n <MsgType><![CDATA[%s]]></MsgType>\n <Content><![CDATA[%s]]></Content>\n <FuncFlag>0</FuncFlag>\n </xml>"; $resultStr = sprintf($textTpl, $fromUserName, $toUserName, time(), 'text', $msg); echo $resultStr; H::app()->end(); }
<link rel="icon" href="<?php echo H::app()->public_url; ?> /images/favicon.ico" sizes="any"> <link href="<?php echo H::app()->public_url; ?> /login/css/login.css" type="text/css" rel="stylesheet"> <script> window.base_url = '<?php echo H::app()->base_url; ?> '; </script> </head> <body> <?php echo $H_VIEW_HTML; ?> <script src="<?php echo H::app()->public_url; ?> /js/jquery.min.js"></script> <script src="<?php echo H::app()->public_url; ?> /js/md5.min.js"></script> <script src="<?php echo H::app()->public_url; ?> /login/js/login.js"></script> </body> </html>
protected static function getKey($key) { return md5(H::app()->base_path) . $key; }
/** * 错误处理 * @param int $code 错误码 * @param string $message 错误消息 * @param string $file 错误文件 * @param int $line 错误行 */ public function handleError($code, $message, $file, $line) { if ($this->_h_config['is_log']) { //$trace = debug_backtrace();//需要时候再用 $log = 'Error Code[' . $code . '] Msg[' . $message . '] ' . $file . ' on line ' . $line; HLog::model()->add($log, HLog::LEVEL_ERROR); Controller::renderErr($message, $file, $line); H::app()->end(); } }
<div id="login_box"> <span id="sys_title"><?php echo H::app()->getConfig('app_name'); ?> </span> <div> <input id="user_account" value="<?php echo $access_token; ?> " class="login_input" placeholder="账号" type="text"> </div> <div> <input id="user_pwd" value="" class="login_input" placeholder="密码" type="password"> </div> <div id="err_msg"></div> <a id="btn_login" href="javascript:;">登录</a> <div id="copyright">© 2015</div> </div>