I have a problem with links from backend to frontend and frontend to backend, which are working differently.
frontend\config\main.php
<?php
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-frontend',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'frontend\controllers',
'components' => [
'session' => [
'name' => 'PHPGESESSID',
'savePath' => __DIR__ . '/../tmp',
],
'user' => [
'enableSession' => true,
'identityClass' => 'common\models\User',
'enableAutoLogin' => false,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager'=>[
'enablePrettyUrl' => false,
'class' => 'yii\web\UrlManager',
'hostInfo' => 'http://localhost/frontend',
],
'urlManagerBackend'=>[
'enablePrettyUrl' => false,
'class' => 'yii\web\UrlManager',
'hostInfo' => 'http://localhost/backend',
'baseUrl' => 'http://localhost/backend',
],
],
'params' => $params,
];
For frontend, the links in the NAVBAR views are:
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']],
['label' => 'Sign in', 'url' => Yii::$app->urlManagerBackend->createUrl('site/login')],
];
The href we get are respectively,
localhost/frontend/site/index
localhost/frontend/site/about
localhost/frontend/site/contact
[color="#FF0000"]localhost/frontend/site/login[/color]
Captcha is working in the contact form in the frontend
Now, backend
backend\config\main.php
<?php
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-backend',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'language' => 'en-US',
'bootstrap' => ['log'],
'modules' => [],
'components' => [
'session' => [
'name' => 'PHPADSESSID',
'savePath' => __DIR__ . '/../tmp',
],
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager'=>[
'enablePrettyUrl' => false,
'class' => 'yii\web\UrlManager',
'hostInfo' => 'http://localhost/backend',
],
'urlManagerFrontend'=>[
'enablePrettyUrl' => true,
'class' => 'yii\web\UrlManager',
'showScriptName'=>false,
'suffix' => '.html',
'hostInfo' => 'http://localhost/frontend',
'baseUrl' => 'http://localhost/frontend',
],
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@common/messages',
'sourceLanguage' => 'en-US',
],
],
],
],
'params' => $params,
];
For backend, the links in the NAVBAR views are:
$menuItems = [
['label' => \Yii::t('appmsg', 'Register'), 'url' => ['/site/register']],
['label' => \Yii::t('appmsg', 'Subscribe'), 'url' => Yii::$app->urlManagerFrontend->createUrl('site/subscribe'),],
['label' => \Yii::t('appmsg', 'Contact us'), 'url' => Yii::$app->urlManagerFrontend->createUrl('site/contact'),],
];
The href we get are respectively,
localhost/backend/site/register
[color="#2E8B57"]localhost/frontend/site/subscribe
localhost/frontend/site/contact[/color]
[color="#FF0000"]Captcha is NOT working in the register form in the frontend, even though the model, action and view are made similar to localhost/frontend/site/contact
[/color]
I tried to add ârequestâ component with âbaseUrlâ but results are not different. I seek some advice to guide me to find my flaw.
thanks in advance.