{ $route = Yii::getAlias((string) $route); if (strncmp($route, '/', 1) === 0) { // absolute route return ltrim($route, '/'); } // relative route if (Yii::$app->controller === null) { throw new InvalidArgumentException("Unable to resolve the relative route: $route. No active controller is available."); } if (strpos($route, '/') === false) { // empty or an action ID return $route === '' ? Yii::$app->controller->getRoute() : Yii::$app->controller->getUniqueId() . '/' . $route; } // relative to module return ltrim(Yii::$app->controller->module->getUniqueId() . '/' . $route, '/');
* @return string the generated URL * @throws InvalidArgumentException a relative route is given while there is no active controller */ public static function toRoute($route, $scheme = false) { $route = (array) $route; $route[0] = static::normalizeRoute($route[0]); if ($scheme !== false) { return static::getUrlManager()->createAbsoluteUrl($route, is_string($scheme) ? $scheme : null); } return static::getUrlManager()->createUrl($route);
* @return string the generated URL * @throws InvalidArgumentException a relative route is given while there is no active controller */ public static function to($url = '', $scheme = false) { if (is_array($url)) { return static::toRoute($url, $scheme); } $url = Yii::getAlias($url); if ($url === '') { $url = Yii::$app->getRequest()->getUrl(); }
if (isset($_GET['redirect']) && $_GET['redirect'] === 'false') { return; } if (isset($_GET['action']) && $_GET['action'] == 'view') { Yii::$app->response->redirect(Url::to(['universities/index', 'type' => 10])); } else { Yii::$app->response->redirect(Yii::$app->request->referrer); } } else { $this->checkActualCountry(); }
{ if (!$this->session) { $this->session = Yii::$app->session; $this->session->open(); } $this->checkCountryInUri(); $this->getCountryEntity(); $this->setLanguage(); parent::init(); }
*/ 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.
$dependencies = $this->resolveDependencies($dependencies, $reflection); if (!$reflection->isInstantiable()) { throw new NotInstantiableException($reflection->name); } if (empty($config)) { return $reflection->newInstanceArgs($dependencies); } $config = $this->resolveDependencies($config); if (!empty($dependencies) && $reflection->implementsInterface('yii\base\Configurable')) { // set $config as the last parameter (existing one will be overwritten)
public function get($class, $params = [], $config = []) { if (isset($this->_singletons[$class])) { // singleton return $this->_singletons[$class]; } elseif (!isset($this->_definitions[$class])) { return $this->build($class, $params, $config); } $definition = $this->_definitions[$class]; if (is_callable($definition, true)) { $params = $this->resolveDependencies($this->mergeParams($class, $params));
{ if (is_string($type)) { return static::$container->get($type, $params); } elseif (is_array($type) && isset($type['class'])) { $class = $type['class']; unset($type['class']); return static::$container->get($class, $params, $type); } elseif (is_callable($type, true)) { return static::$container->invoke($type, $params); } elseif (is_array($type)) { throw new InvalidConfigException('Object configuration must be an array containing a "class" element.'); }
if (isset($this->_definitions[$id])) { $definition = $this->_definitions[$id]; if (is_object($definition) && !$definition instanceof Closure) { return $this->_components[$id] = $definition; } return $this->_components[$id] = Yii::createObject($definition); } elseif ($throwException) { throw new InvalidConfigException("Unknown component ID: $id"); } return null; }
* Since version 2.0.13, if a component isn't defined in the module, it will be looked up in the parent module. * The parent module may be the application. */ public function get($id, $throwException = true) { if (!isset($this->module)) { return parent::get($id, $throwException); } $component = parent::get($id, false); if ($component === null) { $component = $this->module->get($id, $throwException); }
Yii::debug('Bootstrap with Closure', __METHOD__); if (!$component = call_user_func($mixed, $this)) { continue; } } elseif (is_string($mixed)) { if ($this->has($mixed)) { $component = $this->get($mixed); } elseif ($this->hasModule($mixed)) { $component = $this->getModule($mixed); } elseif (strpos($mixed, '\\') === false) { throw new InvalidConfigException("Unknown bootstrapping component ID: $mixed"); } }
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.
defined('YII_DEBUG') or define('YII_DEBUG', true); require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php'; $config = require __DIR__ . '/../config/web.php'; (new yii\web\Application($config))->run();
$_GET = [ 'country' => 'Ru', 'action' => 'view', ]; $_SESSION = [ '__flash' => [], 'country' => 'Ru', ];