Не работает переадрессация между страницами Yii2

Являюсь новичком в Yii2.

Прописал в views/layouts/main.php следующий header:

<div class="container-header">
    <a href="">
        Инстаграм
    </a>
    <a href="">
        Контакты
    </a>
    <a href="/login.php">
        Личный кабинет
    </a>
    <a href="">
        Прайс
    </a>
</div>

Правила в SiteController следующие:

public function behaviors()
{
    return [
        'access' => [
            'class' => AccessControl::className(),
            'rules' => [
                [
                    'actions' => ['logout', 'index', 'login', 'price', 'contacts','record'],
                    'allow' => true,
                    'roles' => ['?'],
                ],
            ],
        ],
        'verbs' => [
            'class' => VerbFilter::className(),
            'actions' => [
                'logout' => ['post'],
            ],
        ],
    ];
}

конфиг:

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],
    'language' => 'ru-RUS',
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'xxx',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => $db,
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>'
            ],
        ],
    ],
    'params' => $params,
];

Проблема заключается в том, что при переходе по данной ссылке (login.php) пишется, что страница не найдена. actionLogin для данной странице также задан.


Ответы (1 шт):

Автор решения: Kirzzz

Так как я это все делал на локальном хосте через PhpStorm, то urlManager нужно было отключить.

В layouts/main.php ссылки нужно было прописывать следующим образом: <?= Url::toRoute('/site/login') ?>

В моем случае все заработало.

→ Ссылка