'url' => null, ]; } } } protected function getNewsDate($page) { preg_match_all('/[0-9]{2,4}/', $page, $matches); $date = mktime($matches[0][3], $matches[0][4], $matches[0][5], $matches[0][1], $matches[0][2], $matches[0][0]); return Yii::$app->formatter->asDatetime($date, "short"); } public function getBack() { return Yii::$app->session->get($this->id . '/back', '/'); } }
} } protected function getNewsDate($page) { preg_match_all('/[0-9]{2,4}/', $page, $matches); $date = mktime($matches[0][3], $matches[0][4], $matches[0][5], $matches[0][1], $matches[0][2], $matches[0][0]); return Yii::$app->formatter->asDatetime($date, "short"); } public function getBack() { return Yii::$app->session->get($this->id . '/back', '/'); }
'label' => Yii::t('portal', 'News'), 'url' => '/' . Yii::$app->language . '/news', ]; if (isset($urlItem[1])) { if ($isPage) { $this->view->params['breadcrumbs'][] = [ 'label' => $this->getNewsDate($urlItem[1]), ]; } else $this->view->params['breadcrumbs'][] = [ 'label' => $urlItem[1], 'url' => count($urlItem) > 2 ? '/' . Yii::$app->language . '/news/' . $urlItem[1] : null, ];
$this->maxUrl = $menuItem['url']; if (isset($menuItem['items']) && count($urlItem) > 0) { //Yii::debug($menuItem['label']); //Yii::debug($menuItem['url']); $burl = is_array($menuItem['url']) ? $menuItem['url'] : [$menuItem['url']]; $this->view->params['breadcrumbs'][] = ['label'=>strip_tags($menuItem['label']),'url'=>$burl]; $this->fillBreadcrumbs($url, $menuItem['items'], $urlItem, $level + 1); } else { //echo $url.' '.$menuItem['branch'].' '.$urlToCompare.'<br>'; $this->view->params['breadcrumbs'][] = strip_tags($menuItem['label']); if (isset($menuItem['title'])) { $this->view->params['pageTitle'] = $menuItem['title']; $this->view->params['pageLabel'] = strip_tags($menuItem['label']);
return Yii::$app->NormalizeMenu([$menu], [], '/news/'); } protected function fillBreadcrumbs($url, $menu, $urlItem, $level = 1) { parent::fillBreadcrumbs($url, $menu, $urlItem, $level = 1); $this->view->params['breadcrumbs'] = []; $isPage = Yii::$app->requestedRoute === 'news/page'; Yii::debug('/' . join('/', $urlItem)); $this->view->params['breadcrumbs'][] = [ 'label' => Yii::t('portal', 'News'), 'url' => '/' . Yii::$app->language . '/news',
if (count($urlItem) && ('/'.$url!==Yii::$app->homeUrl)) { $back = $urlItem; array_pop($back); $this->urlUp = '/'.implode('/',$back); if ($lang && $urlItem[0] == $lang) array_shift($urlItem); $this->fillBreadcrumbs($lang ? "/$lang" : '', Yii::$app->menu, $urlItem); } if (Yii::$app->request->isAjax) return; $this->checkUrl('/'.$url); //Yii::debug(var_export($this->view->params, true)); }
Yii::trace('ajax: '.Yii::$app->request->isAjax); //if (Yii::$app->request->isAjax) return; $this->maxUrl .= $lang; if (!$this->appendMenu && !Yii::$app->request->isAjax) $this->setBreadcrumbs($lang); } public function loadModel($ar, $pk) { $model = $ar::findOne($pk); if ($model === null)
{ //public $back; public function init() { $this->view->params['menu'] = $this->setMenu(); parent::init(); if (!Yii::$app->session->get($this->id . '/back')) { $prevUrl = Yii::$app->session->get('prevUrl', '/'); Yii::$app->session->set($this->id . '/back', $prevUrl); } }
*/ 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.
* @param array $config name-value pairs that will be used to initialize the object properties. */ public function __construct($id, $module, $config = []) { $this->id = $id; $this->module = $module; parent::__construct($config); } /** * {@inheritdoc} * @since 2.0.36 */
$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)
$class = $class->id; } 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));
* @throws InvalidConfigException if the configuration is invalid. * @see \yii\di\Container */ public static function createObject($type, array $params = []) { if (is_string($type)) { return static::$container->get($type, $params); } if (is_callable($type, true)) { return static::$container->invoke($type, $params); }
$className = ltrim($this->controllerNamespace . '\\' . str_replace('/', '\\', $prefix) . $className, '\\'); if (strpos($className, '-') !== false || !class_exists($className)) { return null; } if (is_subclass_of($className, 'yii\base\Controller')) { $controller = Yii::createObject($className, [$id, $this]); return get_class($controller) === $className ? $controller : null; } elseif (YII_DEBUG) { throw new InvalidConfigException('Controller class must extend from \\yii\\base\\Controller.'); } return null;
if (($pos = strrpos($route, '/')) !== false) { $id .= '/' . substr($route, 0, $pos); $route = substr($route, $pos + 1); } $controller = $this->createControllerByID($id); if ($controller === null && $route !== '') { $controller = $this->createControllerByID($id . '/' . $route); $route = ''; } return $controller === null ? false : [$controller, $route];
* @param array $params the parameters to be passed to the action * @return mixed the result of the action. * @throws InvalidRouteException if the requested route cannot be resolved into an action successfully. */ public function runAction($route, $params = []) { $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);
//echo '<br>'.date("Y-m-d Y H:i:s O",time()); $this->language = $this->chooseLanguage(); list($ctl,) = explode('/', $route); if ($ctl!='gpb') $this->setMenu($this->language); //var_dump($route); return parent::runAction($route, $params); } /*public function getMenu() { return $this->_menu; }*/
$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__ . '/../config/main-local.php' ); $app = new common\WebApplication($config); //$qqq = new \yii\web\Application($config); //var_dump ($qqq); $app->run();
$_GET = [ 'lang' => 'ru', 't' => 'view/2007-06-10_18-05-29', ]; $_SESSION = [ '__flash' => [], 'prevUrl' => '', 'curUrl' => '/ru/news/page/view/2007-06-10_18-05-29', 'prevLang' => 'ru', ];