Yii2 高级应用,前端和后端的不同会话与子域 [英] Yii2 Advanced app, different session for frontend and backend with subdomains

查看:24
本文介绍了Yii2 高级应用,前端和后端的不同会话与子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Yii2 应用有问题.我有一个高级应用程序,其中包含不同域(子域)上的前端和后端部分.我使用webvimark用户管理模块,但我认为问题不在它.

I have a problem with my Yii2 app. I have a advanced-app with frontend and backend parts on different domains (subdomain). I use webvimark user management module, but I think the problem is not in it.

前端应用程序 -> domain.com
后端应用程序 -> admin.domain.com

Frontend app -> domain.com
Backend app -> admin.domain.com

所以我在后台登录有问题,它不工作.
我输入登录名和密码,提交表单后我再次看到登录表单.

So I have problem with login in backend, it is not working.
I enter login and password, and after submit form I see login form again.

'user' => [
        'identityClass' => 'webvimarkmodulesUserManagementmodelsUser',
        'enableAutoLogin' => true,
        'identityCookie' => [
            'name'     => '_backendIdentity',
            'domain'     => 'admin.domain.com',
        ],
        'class' => 'webvimarkmodulesUserManagementcomponentsUserConfig',
    ],

'session' => [
        'name' => 'BACKENDSESSID',
        'cookieParams' => [
            'domain'     => 'admin.domain.com',
        ],
    ],

有什么想法吗?

更新 #1: 我的配置位于:/backend/config/main.php
更新 #2:在子域上传输后端时出现问题

Update #1: My config located: /backend/config/main.php
Update #2: There was a problem when transferring backend on a subdomain

推荐答案

好的,模块配置有问题,前端配置错误.

Okey, there was a problem with the configuration of the module, as well as the wrong config in the frontend.

后端:

'user' => [
        'identityClass' => 'webvimarkmodulesUserManagementmodelsUser',
        'enableAutoLogin' => true,
        'identityCookie' => [
            'name' => '_backendIdentity',
            'domain' => 'backend.test.dev',
        ],
        'class' => 'webvimarkmodulesUserManagementcomponentsUserConfig',
        'on afterLogin' => function ($event) {
            webvimarkmodulesUserManagementmodelsUserVisitLog::newVisitor($event->identity->id);
        },
    ],
    'session' => [
        'name' => 'BACKENDSESSID',
        'cookieParams' => [
            'domain' => 'backend.test.dev',
        ],
    ],

前端:

'user' => [
        'identityClass' => 'webvimarkmodulesUserManagementmodelsUser',
        'enableAutoLogin' => true,
        'identityCookie' => [
            'name'     => '_frontendIdentity',
            'path'     => '/',
        ],
        'class' => 'webvimarkmodulesUserManagementcomponentsUserConfig',
        'on afterLogin' => function ($event) {
            webvimarkmodulesUserManagementmodelsUserVisitLog::newVisitor($event->identity->id);
        }
    ],
    'session' => [
        'name' => 'FRONTENDSESSID',
        'cookieParams' => [
            'path'     => '/',
        ],
    ],

这篇关于Yii2 高级应用,前端和后端的不同会话与子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆