0

I have setup Yii2 nested module and I want to set different configuration and each modules has own component and other settings with there own models

Like in School Management System, I have created a nested module like V1 is my API (main module) and under these, I have created a Student module, Teacher module, Parent module, driver module, admin module each has a different table and different model. I want to login differently with each user like..

API calls for each

https://example.com/v1/admin/login

https://example.com/v1/student/login

https://example.com/v1/parent/login

https://example.com/v1/user/login

https://example.com/v1/driver/login

How can I manage these login and their own configuration?

enter image description here

Thanks

Jitendra

Jitendra Y
  • 25
  • 11
  • check the logic behind frontend and backend of yii2 advanced same logic you can apply here. – Amitesh Kumar Feb 03 '20 at 08:51
  • I already try but this is the basic Yii2 setup and under the module, I need to add another module and also these module work like another app – Jitendra Y Feb 10 '20 at 11:59

1 Answers1

0

In the module Class you can set components, aliases and other settings and using something like this:

Here is an example for the admin module:

class Admin extends Module
{

    // ...

    /**
     * {@inheritdoc}
     */
    public function init()
    {
        parent::init();

        // custom initialization code goes here

        $this->setComponents([
            // array of components
        ]);

        // ...
    }
}

or if you prefer you can set the components like this

$this->components = [
    // array of components
]);

if you are using nested modules, you are already specifying "settings" for the module - i.e all sub modules

To use different login for all modules when specifying components set different name for the identityCookie of the user component for each module.

Example for admin module:

$this->components => [
    'user' => [
        'identityClass' => 'common\models\User',
        'enableAutoLogin' => true,
        'identityCookie' => ['name' => '_identity-admin', 'httpOnly' => true],
    ],
    // ... other components
tsanchev
  • 407
  • 5
  • 13