Skip to content

Latest commit

 

History

History
112 lines (87 loc) · 3.44 KB

user-types.md

File metadata and controls

112 lines (87 loc) · 3.44 KB

User Types


🔙 guide

User types allow you to control your application layout and view settings for different types of users. To add/configure the user types for your application, extend the comyii\user\models\User class. Then define your user types as constants and then add them to the module configuration.

For example, let's consider if we want two user types, one for customers, and another for vendors.

User Types Setup

Step 1: Extend the User model as shown below:

namespace common\models;
class User extends \comyii\user\models\User
{
    const TYPE_CUSTOMER = 1;
    const TYPE_VENDOR = 2;
}

Step 2: Then update your module configuration for the user types:

    'modules' => [
        'user' => [
            'class' => 'comyii\user\Module',
            'userTypes'=>[
                common\models\User::TYPE_CUSTOMER => 'customer',
                common\models\User::TYPE_VENDOR => 'vendor'
            ],
        ],
    ],

🔙 top | 🔙 guide

User Type Custom Layouts

    'modules' => [
        'user' => [
            'class' => 'comyii\user\Module',
            'userTypes'=>[
                common\models\User::TYPE_CUSTOMER => 'customer',
                common\models\User::TYPE_VENDOR => 'vendor'
            ],
            'layoutSettings'=>[
                common\models\User::TYPE_CUSTOMER => [
                    comyii\user\Module::VIEW_PROFILE_INDEX => '@frontend/views/layouts/customer',
                    comyii\user\Module::VIEW_PROFILE_UPDATE => '@frontend/views/layouts/customer',
                    comyii\user\Module::VIEW_PASSWORD => '@frontend/views/layouts/customer',
                ],
                common\models\User::TYPE_VENDOR => [
                    comyii\user\Module::VIEW_PROFILE_INDEX => '@frontend/views/layouts/vendor',
                    comyii\user\Module::VIEW_PROFILE_UPDATE => '@frontend/views/layouts/vendor',
                    comyii\user\Module::VIEW_PASSWORD => '@frontend/views/layouts/vendor',
                ],
            ],
        ],
    ],

🔙 top | 🔙 guide

User Type Custom Views

    'modules' => [
        'user' => [
            'class' => 'comyii\user\Module',
            'userTypes'=>[
                common\models\User::TYPE_CUSTOMER => 'customer',
                common\models\User::TYPE_VENDOR => 'vendor'
            ],
            'viewSettings' => [
                common\models\User::TYPE_VENDOR => [
                    comyii\user\Module::VIEW_PROFILE_INDEX => '@frontend/views/vendor/profile'
                ]
            ],
        ],
    ],

🔙 top | 🔙 guide

User Type Routes

Any custom user types defined in the config will have a registration page using the following url rule:

'register/<type:>' => 'account/register',

Note that these can also be customized by updating the urlRules in the module configuration.

🔙 top | 🔙 guide

Examples

🔙 top | 🔙 guide