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.
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'
],
],
],
'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',
],
],
],
],
'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'
]
],
],
],
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.