/** * @inheritdoc */ public function parseRequest($manager, $request) { $pathInfo = trim($request->getPathInfo(), '/'); if (empty($pathInfo) or $pathInfo == Pages::INDEX_CODE) { return false; } $sections = explode("/", $pathInfo); $parent = Pages::findOne(TActiveRecord::ROOT_ID); foreach ($sections as $section) { $model = $parent->children(1)->published()->andWhere(["code" => $section])->one(); if (!$model) { return false; } else { $parent = $model; } } if (!empty($model)) { return [$this->route, ['model' => $model]]; } return false; // this rule does not apply }
/** * Создание url * @param array $model массив результатов * @return string */ public function createUrl(array $model) { switch ($model[$this->modelKey]) { case "News": $url = Url::toRoute(["/news/news/detail", "code" => $model["code"], "section" => $model["section_code"]]); break; case "Pages": $m = \app\modules\main\models\Pages::findOne($model["item_id"]); if ($m) { $url = Url::toRoute(["/main/pages/index", "model" => $m]); } else { $url = ""; } break; case "Catalog": $url = Url::toRoute(["/catalog/catalog/detail", "code" => $model["code"], "section" => $model["section_code"]]); break; default: $url = ""; } return $url; }
/** * Тест перемещения текстовой страницы */ public function testReplacePage() { $model = Pages::findOne(["code" => "test"]); $parentModel = Pages::findOne(["code" => "main"]); $route = $this->replaceRoute; $this->postRequest($route); $_POST = ["selection" => [$model->id], "replace_parent_id" => $parentModel->id]; Yii::$app->runAction($route); $model->refresh(); $newParent = $model->parents(1)->one(); $this->specify('parent of model has changed', function () use($parentModel, $newParent) { $this->assertTrue($parentModel->id == $newParent->id); }); }