* @since 2.0.6 */ protected static function handleJsonError($lastError) { if ($lastError === JSON_ERROR_NONE) { return; } if (PHP_VERSION_ID >= 50500) { throw new InvalidArgumentException(json_last_error_msg(), $lastError); } foreach (static::$jsonErrorMessages as $const => $message) { if (defined($const) && constant($const) === $lastError) { throw new InvalidArgumentException($message, $lastError); } } throw new InvalidArgumentException('Unknown JSON encoding/decoding error.');
} elseif (static::$prettyPrint === false) { $options &= ~JSON_PRETTY_PRINT; } $json = json_encode($value, $options); restore_error_handler(); static::handleJsonError(json_last_error()); return $expressions === [] ? $json : strtr($json, $expressions); } /** * Encodes the given value into a JSON string HTML-escaping entities so it is safe to be embedded in HTML code.
public function getQueryParams() { $query_params = Yii::$app->request->queryParams; unset($query_params['seo']); return Json::encode($query_params); } public function renderSeoLink() { if (!Yii::$app->user->isGuest && !Yii::$app->request->isAjax && Yii::$app->controller->module->id !== 'admin' && Yii::$app->errorHandler->errorAction !== $this->getRoute()) { Yii::$app->view->on(View::EVENT_END_BODY, function () {
$route = $this->getRoute(); if (Yii::$app->controller->module->id === 'admin' || Yii::$app->errorHandler->errorAction === $route) { return true; } $query_params = $this->getQueryParams(); if (Yii::$app->request->get('seo')) { $seo = new \app\models\Seo([ 'route' => $route, 'query_params' => $query_params, ]);
$event->sender = $this; } $event->handled = false; $event->name = $name; foreach ($eventHandlers as $handler) { $event->data = $handler[1]; call_user_func($handler[0], $event); // stop further handling if the event is handled if ($event->handled) { return; } } }
* @param Action $action the action to be executed. * @return bool whether the action should continue to be executed. */ public function beforeAction($action) { $event = new ActionEvent($action); $this->trigger(self::EVENT_BEFORE_ACTION, $event); return $event->isValid; } /** * This method is invoked right after an action within this module is executed. *
$modules = []; $runAction = true; // call beforeAction on modules foreach ($this->getModules() as $module) { if ($module->beforeAction($action)) { array_unshift($modules, $module); } else { $runAction = false; break; } }
$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); if ($oldController !== null) { Yii::$app->controller = $oldController; } return $result; }
$params = $this->catchAll; unset($params[0]); } try { Yii::debug("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } $response = $this->getResponse(); if ($result !== null) {
{ 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();
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 = [ 'PGID' => '191', 'DOK' => '��������� ��������, ������ �����', ]; $_SESSION = [ '__flash' => [], ];