return; } if (!empty($this->masters)) { $db = $this->openFromPool($this->masters, $this->masterConfig); if ($db !== null) { $this->pdo = $db->pdo; return; } else { throw new InvalidConfigException('None of the master DB servers is available.'); } } if (empty($this->dsn)) { throw new InvalidConfigException('Connection::dsn cannot be empty.'); } $token = 'Opening DB connection: ' . $this->dsn; try { Yii::info($token, __METHOD__);
* Returns the PDO instance for the currently active master connection. * This method will open the master DB connection and then return [[pdo]]. * @return PDO the PDO instance for the currently active master connection. */ public function getMasterPdo() { $this->open(); return $this->pdo; } /** * Returns the currently active slave connection. * If this method is called the first time, it will try to open a slave connection when [[enableSlaves]] is true.
* is available and `$fallbackToMaster` is false. */ public function getSlavePdo($fallbackToMaster = true) { $db = $this->getSlave(false); if ($db === null) { return $fallbackToMaster ? $this->getMasterPdo() : null; } else { return $db->pdo; } } /**
public function getDriverName() { if ($this->_driverName === null) { if (($pos = strpos($this->dsn, ':')) !== false) { $this->_driverName = strtolower(substr($this->dsn, 0, $pos)); } else { $this->_driverName = strtolower($this->getSlavePdo()->getAttribute(PDO::ATTR_DRIVER_NAME)); } } return $this->_driverName; } /**
*/ public function getSchema() { if ($this->_schema !== null) { return $this->_schema; } else { $driver = $this->getDriverName(); if (isset($this->schemaMap[$driver])) { $config = !is_array($this->schemaMap[$driver]) ? ['class' => $this->schemaMap[$driver]] : $this->schemaMap[$driver]; $config['db'] = $this; return $this->_schema = Yii::createObject($config); } else {
/** * Returns the query builder for the current DB connection. * @return QueryBuilder the query builder for the current DB connection. */ public function getQueryBuilder() { return $this->getSchema()->getQueryBuilder(); } /** * Obtains the schema information for the named table. * @param string $name table name. * @param boolean $refresh whether to reload the table schema even if it is found in the cache.
*/ public function createCommand($db = null) { if ($db === null) { $db = Yii::$app->getDb(); } list ($sql, $params) = $db->getQueryBuilder()->build($this); return $db->createCommand($sql, $params); } /** * Prepares for building SQL.
* If this parameter is not given, the `db` application component will be used. * @return array|boolean the first row (in terms of an array) of the query result. False is returned if the query * results in nothing. */ public function one($db = null) { return $this->createCommand($db)->queryOne(); } /** * Returns the query result as a scalar value. * The value returned will be the first column in the first row of the query results. * @param Connection $db the database connection used to generate the SQL statement.
$data = (new \yii\db\Query()) ->select('*') ->from(self::tableName()) ->where($where) ->orderBy('rand()') ->groupBy('hid') ->one(); } else { $key = 'one_people_'.$uid.LANG_SET.PROTOCOL; if ($data = \Yii::$app->cache->get($key)) { return $data; } $where['hid'] = $uid;
} public function actionIndex() { ini_set('max_execution_time', 300); $peopleModel = new PeopleInformation; $peopleInfo = $peopleModel->getInfoById(true); //获取默认人物信息 $peopleInfoImg = $peopleModel->getFields('portraits,hid AS id'); //获取人物头像 $peopleInfoImg = $this->orderInfo($peopleInfoImg, $peopleInfo['hid']); $micend = \Yii::$app->request->get('micend', 0);//桌面端传递参数 $articleModel = new News_Multi_Language; $eventList2 = $articleModel->getArticleList(16,3,true,0,LANG_SET,4);//EVENT
$args = $this->controller->bindActionParams($this, $params); Yii::trace('Running action: ' . get_class($this->controller) . '::' . $this->actionMethod . '()', __METHOD__); if (Yii::$app->requestedParams === null) { Yii::$app->requestedParams = $args; } return call_user_func_array([$this->controller, $this->actionMethod], $args); } }
} $result = null; if ($runAction && $this->beforeAction($action)) { // run the action $result = $action->runWithParams($params); $result = $this->afterAction($action, $result); // call afterAction on modules foreach ($modules as $module) { /* @var $module Module */
$parts = $this->createController($route); if (is_array($parts)) { /* @var $controller Controller */ list($controller, $actionID) = $parts; $oldController = Yii::$app->controller; Yii::$app->controller = $controller; $result = $controller->runAction($actionID, $params); Yii::$app->controller = $oldController; return $result; } else { $id = $this->getUniqueId(); throw new InvalidRouteException('Unable to resolve the request "' . ($id === '' ? $route : $id . '/' . $route) . '".');
$params = $this->catchAll; unset($params[0]); } try { Yii::trace("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } else { $response = $this->getResponse(); if ($result !== null) { $response->data = $result;
try { $this->state = self::STATE_BEFORE_REQUEST; $this->trigger(self::EVENT_BEFORE_REQUEST); $this->state = self::STATE_HANDLING_REQUEST; $response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send();
$config = require(__DIR__ . '/../config/web.php'); //check LANGUAGE require(__DIR__ . '/../filters/LangFilter.php'); //阿里大鱼 require(__DIR__ . '/../vendor/alidayu/vendor/autoload.php'); (new yii\web\Application($config))->run();