Yii2 advanced framework 2.0.6.
I am trying to learn how to setup the app file system on a ‘live’ server.
This is the file structure I am using:
- yii2app/
- frontend/
- backend/
- common/
- .. other folders..
- admin/
- assets/
- css/
- index.php
- assets/
- css/
- index.php
URL generated:
http://www.example.com/admin
or http://www.example.com
I have made corresponding changes to both the index.php in the root directory: yii-app/
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/common/config/bootstrap.php');
require(__DIR__ . '/frontend/config/bootstrap.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/common/config/main.php'),
require(__DIR__ . '/common/config/main-local.php'),
require(__DIR__ . '/frontend/config/main.php'),
require(__DIR__ . '/frontend/config/main-local.php')
);
and in the admin directory, yii-app/admin
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../common/config/bootstrap.php');
require(__DIR__ . '/../backend/config/bootstrap.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../common/config/main.php'),
require(__DIR__ . '/../common/config/main-local.php'),
require(__DIR__ . '/../backend/config/main.php'),
require(__DIR__ . '/../backend/config/main-local.php')
);
.
The issue I am experiencing is that after successfully logging into the app as a ‘user’ I’ve noticed that in the navbar ‘Login’ does not change to ‘Logout (user name)’.
Also if I go to click on ‘Login’ again, there is an error
The section highlighted in the error message:
1. in /Users/***********/yii-app/vendor/yiisoft/yii2/web/User.php at line 614
{
$session = Yii::$app->getSession();
$id = $session->getHasSessionId() || $session->getIsActive() ? $session->get($this->idParam) : null;
if ($id === null) {
$identity = null;
} else {
/* @var $class IdentityInterface */
$class = $this->identityClass;
614 $identity = $class::findIdentity($id);
}
$this->setIdentity($identity);
if ($id
The user ‘id’ corresponds with the ‘User’, ie, user ‘id’ = 11.
$_SESSION = [
'__flash' => [],
'__id' => 11,
];
The only way to rectify this ‘error’ is to clear the browser history.
The above may indicate that this is a session issue.
Based on information I have gleaned from the web I have created two session ids, one for frontend and one for the backend. The backend is for admin purposes and it works fine. Below is the setup for FRONTENDSESSID in yii-app\frontend\config\main.php.
'id' => 'app-frontend',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'frontend\controllers',
'defaultRoute' => 'pages/index',
'components' => [
'request' => [
'csrfParam' => '_frontendCSRF',
'csrfCookie' => [
'httpOnly' => true,
'path' => '',
],
],
'user' => [
'identityClass' => [
'common\models\User',
'enableAutoLogin' => true,
],
'identityCookie' => [
'name' => '_frontendIdentity',
'path' => '',
'httpOnly' => true,
],
],
'session' => [
'name' => 'FRONTENDSESSID',
'cookieParams' => [
'path' => '',
],
],
..
..
..
The only difference with BACKENDSESSID is
'path' => '/admin',
This part of the app works fine, however any image in the admin section is broken.
Perhaps I am conflating the issues here, or maybe both issues are linked??
Does anyone know how to create a ‘live’ setup that is secure and workable?
The information I have seen seems to be contradictory or incomplete, especially for the novice Yii users.