/** * 得到实例化的对象. * 为每个数据库建立一个连接 * 如果连接超时,将会重新建立一个连接 * @param array $config * @param int $dbId * @return \iphp\db\Redis */ public static function getInstance($config, $attr = array()) { //如果是一个字符串,将其认为是数据库的ID号。以简化写法。 if (!is_array($attr)) { $dbId = $attr; $attr = array(); $attr['db_id'] = $dbId; } $attr['db_id'] = $attr['db_id'] ? $attr['db_id'] : 0; if (!is_array($config)) { $config = App::getApp()->getConfig($config); } $k = md5(implode('', $config) . $attr['db_id']); if (!static::$_instance[$k] instanceof self) { //static::$_instance[$k]->close(); static::$_instance[$k] = new self($config, $attr); static::$_instance[$k]->k = $k; static::$_instance[$k]->dbId = $attr['db_id']; //如果不是0号库,选择一下数据库。 if ($attr['db_id'] != 0) { static::$_instance[$k]->select($attr['db_id']); } } elseif (time() > static::$_instance[$k]->expireTime) { static::$_instance[$k]->close(); static::$_instance[$k] = new self($config, $attr); static::$_instance[$k]->k = $k; static::$_instance[$k]->dbId = $attr['db_id']; //如果不是0号库,选择一下数据库。 if ($attr['db_id'] != 0) { static::$_instance[$k]->select($attr['db_id']); } } return static::$_instance[$k]; }
private function checkExistingSmiles($url, $method) { if (!array_key_exists($url, \App::smiles()[$method])) { return FALSE; } if (\App::smiles()[$method][$url][1] instanceof \Closure) { return call_user_func(\App::smiles()[$method][$url][1]); } $st = explode('@', \App::smiles()[$method][$url][1]); if (count($st) != 2) { throw new \Exception('Wrong controller declaration.'); } $realController = 'App\\Controller\\' . $st[0]; $init = new $realController(\App::getApp()); $init->setControllerAction($st[1]); return $init; }
<?php // change the following paths if necessary $app = dirname(__FILE__) . '/App.php'; $autoload = dirname(__FILE__) . '/autoload.php'; $config = dirname(__FILE__) . '/config/main.php'; require_once $app; require_once $autoload; App::getApp($config)->run();
/** * 记录日志 * * @param string $msg 记录的信息 * @param int $level * @param string $sourceName * @param string $actorName * @param string $actorId * @param mix $exts * @return boolean */ public function log($msg, $level = 0, $sourceName = "", $actorName = "", $actorId = "", $exts = null, $extsInt = null) { $rev = false; $datetime = date("Y-m-d H:i:s"); $timestamp = time(); $ip = $_SERVER['REMOTE_ADDR']; if (Watt_Session::getSession()) { //如果是岗位用户 那么还用原来的用户ID 2007-10-24 john if (@$_SESSION["shanggang"]) { $yh_id = $_SESSION["old_user_id"]; $yhs = TpmYonghuPeer::retrieveByPK($yh_id); $user_id = $yhs->getYhId(); $user_name = $yhs->getYhZhanghu(); $c = new Criteria(); $c->add(TpmYonghu2juesePeer::YH_ID, $yh_id); $jsids = TpmYonghu2juesePeer::doSelectOne($c); if ($jsids) { $js_id = $jsids->getJsId(); $c = new Criteria(); $c->add(TpmJuesePeer::JS_ID, $js_id); $jueses = TpmJuesePeer::doSelectOne($c); if ($jueses) { $user_js_id = $jueses->getJsId(); $user_js_mingcheng = $jueses->getJsMingcheng(); } } } else { $user_id = Watt_Session::getSession()->getUserId(); $user_name = Watt_Session::getSession()->getUserName(); $user_js_id = Watt_Session::getSession()->getRoleId(); $user_js_mingcheng = Watt_Session::getSession()->getRoleName(); } /*$session_id = Watt_Session::getSession()->getUserId(); $session_name = Watt_Session::getSession()->getUserName(); $js_id = Watt_Session::getSession()->getRoleId(); $js_mingcheng = Watt_Session::getSession()->getRoleName(); */ $session_id = $user_id; $session_name = $user_name ? $user_name : $actorName; $js_id = $user_js_id; $js_mingcheng = $user_js_mingcheng; } else { $session_id = ''; $session_name = $actorName; $js_id = ''; $js_mingcheng = ''; } $app = App::getApp(); $app->_add($this->_logName, array('yh_id' => $session_id, 'yh_zhanghu' => chks($session_name), 'js_id' => $js_id, 'js_mingcheng' => chks($js_mingcheng), 'rz_level' => $level, 'rz_ip' => $ip, 'rz_type' => chks($sourceName), 'rz_ruanjian' => chks($_SERVER["HTTP_USER_AGENT"]), 'rz_laiyuan' => isset($_SERVER["HTTP_REFERER"]) ? chks($_SERVER["HTTP_REFERER"]) : null, 'rz_neirong' => chks($msg), 'rz_dizhi' => chks($_SERVER['REQUEST_URI']), 'rz_qita_vchar' => chks($exts), 'rz_qita_int' => chks($extsInt), 'created_at' => $timestamp)); /* $log = new TpmRizhi(); $log->setYhId( $session_id ); //用户名 $log->setYhZhanghu( $session_name ); $log->setRzLevel( $level ); $log->setRzIp( $ip ); $log->setRzRuanjian( $_SERVER["HTTP_USER_AGENT"] ); $log->setRzType( $sourceName ); //即日志的逻辑标示 if( isset( $_SERVER["HTTP_REFERER"] ) ){ $log->setRzLaiyuan( $_SERVER["HTTP_REFERER"] ); } $log->setRzNeirong( $msg ); $log->setRzDizhi($_SERVER['REQUEST_URI']); $log->setRzQitaVchar( $exts ); $log->setCreatedAt( $timestamp ); $rev = $log->save();*/ /* rz_id yh_id yh_zhanghu rz_level rz_ip rz_type rz_ruanjian rz_laiyuan rz_neirong rz_dizhi rz_qita_vchar rz_qita_int created_at */ return $rev; }
<?php $user_Id = Yii::app()->user->id; ?> <?php echo $form->errorSummary($model); ?> <!-- array('id_users'=>$user_Id)--> <?php //echo $form->textFieldControlGroup($model,'id_app',array('span'=>5)); ?> <p><h4>App<h4></p> <?php echo $form->dropDownList($model, 'id_app', App::getApp(), array('ajax' => array('type' => 'POST', 'url' => CController::createUrl('Runs/ListarPlataforma'), 'update' => '#' . CHtml::activeId($model, 'id_platform')), 'prompt' => 'Select')); ?> <br/><br/> <?php /*echo $form->dropDownListControlGroup($model,'id_platform',array(),array('id'=>'plat','empty'=>'Choose a platform'));*/ ?> <?php echo $form->dropDownListControlGroup($model, 'id_platform', CHtml::listData(Platforms::model()->findAll(), 'id', 'name'), array('prompt' => 'Selected')); ?>