Including a Compoment only After Lgin In yii2

57 views Asked by At

So I am trying to use the Admin Lte Package with Yii2 Basic. I have followed a few tutorials online on how to install it. It looks awesome after installation but I have a problem. My Issue is that, I want this new View to work only when the user is authenticated else, it should follow the default Yii2 Application. How do I condition this in the web.php or if there's another way out, I will like to know.

Config/web.php 
    'view' => [
        'theme' => [
            'pathMap' => [
                '@app/views' => '@vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app'
            ],
         ], 
    ],
1

There are 1 answers

0
Alexey On

As an idea, you may create 2 entry points:

  • @app/web/index.php (let's call it main)
  • @app/web/adminlte.php (let's call it adminlte)

index.php will include its own config file (in which there is no adminlte-implementation).
adminlte.php will connect its config file (in which has adminlte-implementation). Both entry points will trigger Application::run() to run Yii-applications.

Configure URL splitting on the web server side. For example:

  • example.com --> index.php
  • cp.example.com --> adminlte.php

or

  • example.com/cp/ --> adminlte.php
  • example.com --> index.php or in some other way that you like.

Plus, add redirects from one Application to another: If the user opene URL based adminlte and he is not authorized, redirect him to main. If the user opene URL based main and he is authorized, redirect him to adminlte.

As a result, you get 2 entry points (2 separate Yii applications). But at the same time, they will be able to work without problems with the same database, and the same codebase (models, auth, etc).