{ if ($this->getIsActive()) { return; } $this->registerSessionHandler(); $this->setCookieParamsInternal(); YII_DEBUG ? session_start() : @session_start(); if ($this->getUseStrictMode() && $this->_forceRegenerateId) { $this->regenerateID(); $this->_forceRegenerateId = null; } if ($this->getIsActive()) { Yii::info('Session started', __METHOD__); $this->updateFlashCounters();
} $this->registerSessionHandler(); $this->setCookieParamsInternal(); YII_DEBUG ? session_start() : @session_start(); if ($this->getUseStrictMode() && $this->_forceRegenerateId) { $this->regenerateID(); $this->_forceRegenerateId = null; }
* @param string $key the session variable name * @param mixed $defaultValue the default value to be returned when the session variable does not exist. * @return mixed the session variable value, or $defaultValue if the session variable does not exist. */ public function get($key, $defaultValue = null) { $this->open(); return isset($_SESSION[$key]) ? $_SESSION[$key] : $defaultValue; } /** * Adds a session variable. * If the specified name already exists, the old value will be overwritten.
} return Yii::$app->session->set($key, $val); } public function get($key, $reflush) { return Yii::$app->session->get($key); } public function remove($key) { return Yii::$app->session->remove($key); }
} return $this->_session->set($key, $val, $timeout); } public function get($key, $reflush=false) { return $this->_session->get($key, $reflush); } public function remove($key) { return $this->_session->remove($key); }
/** * 得到当前的货币。 */ public function getCurrentCurrency() { if (!$this->_currentCurrencyCode) { $this->_currentCurrencyCode = Yii::$service->session->get(self::CURRENCY_CURRENT); } return $this->_currentCurrencyCode; } /**
throw new InvalidConfigException('defautlt currency must config'); } if (!$this->baseCurrecy) { throw new InvalidConfigException('base currency must config'); } if (!$this->getCurrentCurrency()) { if (!$currencyCode) { $currencyCode = $this->defaultCurrency; } $this->setCurrentCurrency($currencyCode); } }
// init store currency. if (isset($store['currency']) && !empty($store['currency'])) { $currency = $store['currency']; } else { $currency = ''; } Yii::$service->page->currency->initCurrency($currency); /** * current domain is config is store config. */ $init_complete = 1; $this->thirdLogin = isset($store['thirdLogin']) ? $store['thirdLogin'] : []; /**
// 初始化的bootstrap public function bootstrap($app) { if ($this->appName == 'appadmin') { Yii::$service->admin->bootstrap($app); } else { Yii::$service->store->bootstrap($app); } } // 得到配置值 /** * @param $key | string, 配置的主Key * @param $subKey | string, 配置的子key
if (!isset($component)) { $component = Yii::createObject($mixed); } if ($component instanceof BootstrapInterface) { Yii::debug('Bootstrap with ' . get_class($component) . '::bootstrap()', __METHOD__); $component->bootstrap($this); } else { Yii::debug('Bootstrap with ' . get_class($component), __METHOD__); } } }
protected function bootstrap() { $request = $this->getRequest(); Yii::setAlias('@webroot', dirname($request->getScriptFile())); Yii::setAlias('@web', $request->getBaseUrl()); parent::bootstrap(); } /** * Handles the specified request. * @param Request $request the request to be handled * @return Response the resulting response
/** * {@inheritdoc} */ public function init() { $this->state = self::STATE_INIT; $this->bootstrap(); } /** * Initializes extensions and executes bootstrap components. * This method is called by [[init()]] after the application has been fully configured. * If you override this method, make sure you also call the parent implementation.
*/ public function __construct($config = []) { if (!empty($config)) { Yii::configure($this, $config); } $this->init(); } /** * Initializes the object. * This method is invoked at the end of the constructor after the object is initialized with the * given configuration.
$this->state = self::STATE_BEGIN; $this->preInit($config); $this->registerErrorHandler($config); Component::__construct($config); } /** * Pre-initializes the application. * This method is called at the beginning of the application constructor. * It initializes several important application properties.
* 添加fecshop的服务 ,Yii::$service , 将services的配置添加到这个对象。 * 使用方法:Yii::$service->cms->article; * 上面的例子就是获取cms服务的子服务article。 */ new fecshop\services\Application($config); $application = new yii\web\Application($config); $application->run();