总的来说,我制作了一个布局,一个带有指向网站其他页面的链接的标题。第一次转换时一切正常,或者如果您返回到主页,但如果您继续并转到另一个页面,我们会得到 404。发生这种情况是因为上一页的控制器附加到了新的 URL。
例子
我们第一次去:address/web/controller/action
我们转到另一个页面或点击同一页面:
地址/web/previouscontroller/控制器/动作
我们转到另一个页面或再次点击同一页面:
地址/web/previouscontroller/previouscontroller/控制器/动作
如此反复,或者返回主页。我甚至不知道如何正确地表述这一点,以便搜索引擎能够正确理解我的意思。
布局:
<?php
/** @var yii\web\View $this */
/** @var string $content */
use app\assets\AppAsset;
use yii\helpers\Html;
use yii\helpers\Url;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>" class="h-100">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<?php $this->registerCsrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body class="d-flex flex-column h-100">
<?php $this->beginBody() ?>
<header class="header">
<div class="container">
<div class="burger__menu">
<span></span>
</div>
<div class="logo">
<a href="<?=Url::home()?>"><?= Html::img('@web/img/orig_use.png', ['alt' => 'логотип']) ?></a>
</div>
<nav class="menu">
<ul>
<li class="header__menu">
<a href="<?=Url::to('about/about-view')?>">о нас</a>
</li>
<li class="header__menu">
<a href="<?=Url::to('games/games-view')?>">игры</a>
</li>
<li class="header__menu">
<a href="<?=Url::to('news/news-view')?>">новости</a>
</li>
<li class="header__menu">
<a href="<?=Url::to('jobs/jobs-view')?>">работа</a>
</li>
</ul>
</nav>
<div class="registration__and__themes">
<ul>
<li class="header__icons">
<button><?= Html::img('@web/img/translate_icon.svg', ['alt' => 'перевод сайта']) ?></button>
</li>
<li class="header__icons">
<button><?= Html::img('@web/img/swap_temes_icon.svg', ['alt' => 'смена темы сайта']) ?></button>
</li>
</ul>
</div>
</div>
</header>
<?= $content ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
例如,一个控制器,它们是相同的:
<?php
namespace app\controllers;
use yii\web\Controller;
?>
<?php
class GamesController extends Controller{
public function actionGamesView(){
return $this->render("games");
}
}
?>