0
votes

I get the following error while configurating the yii2-module in advanced template:

exception 'yii\base\UnknownPropertyException' with message 'Getting 

unknown property: common\models\User::status' in D:\Programes instal.lats\xampp\htdocs\yiitester\vendor\yiisoft\yii2\base\Component.php:143
Stack trace:
#0 D:\Programes instal.lats\xampp\htdocs\yiitester\vendor\yiisoft\yii2\db\BaseActiveRecord.php(246): yii\base\Component->__get('status')
#1 D:\Programes instal.lats\xampp\htdocs\yiitester\vendor\yiisoft\yii2\validators\DefaultValueValidator.php(46): yii\db\BaseActiveRecord->__get('status')
#2 D:\Programes instal.lats\xampp\htdocs\yiitester\vendor\yiisoft\yii2\validators\Validator.php(238): yii\validators\DefaultValueValidator->validateAttribute(Object(common\models\User), 'status')
#3 D:\Programes instal.lats\xampp\htdocs\yiitester\vendor\yiisoft\yii2\base\Model.php(333): yii\validators\Validator->validateAttributes(Object(common\models\User), Array)
#4 D:\Programes instal.lats\xampp\htdocs\yiitester\vendor\yiisoft\yii2\db\ActiveRecord.php(416): yii\base\Model->validate(NULL)
#5 D:\Programes instal.lats\xampp\htdocs\yiitester\vendor\yiisoft\yii2\db\BaseActiveRecord.php(582): yii\db\ActiveRecord->insert(true, NULL)
#6 D:\Programes instal.lats\xampp\htdocs\yiitester\frontend\models\SignupForm.php(51): yii\db\BaseActiveRecord->save()
#7 D:\Programes instal.lats\xampp\htdocs\yiitester\frontend\controllers\SiteController.php(123): frontend\models\SignupForm->signup()
#8 [internal function]: frontend\controllers\SiteController->actionSignup()
#9 D:\Programes instal.lats\xampp\htdocs\yiitester\vendor\yiisoft\yii2\base\InlineAction.php(55): call_user_func_array(Array, Array)
#10 D:\Programes instal.lats\xampp\htdocs\yiitester\vendor\yiisoft\yii2\base\Controller.php(151): yii\base\InlineAction->runWithParams(Array)
#11 D:\Programes instal.lats\xampp\htdocs\yiitester\vendor\yiisoft\yii2\base\Module.php(455): yii\base\Controller->runAction('signup', Array)
#12 D:\Programes instal.lats\xampp\htdocs\yiitester\vendor\yiisoft\yii2\web\Application.php(83): yii\base\Module->runAction('site/signup', Array)
#13 D:\Programes instal.lats\xampp\htdocs\yiitester\vendor\yiisoft\yii2\base\Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#14 D:\Programes instal.lats\xampp\htdocs\yiitester\frontend\web\index.php(18): yii\base\Application->run()
#15 {main}

I have followed these instructions:

https://github.com/dektrium/yii2-user/blob/master/docs/getting-started.md

https://github.com/dektrium/yii2-user/blob/master/docs/usage-with-advanced-template.md

Installed with composer:

composer require "dektrium/yii2-user:0.9.*@dev"

And edited the required files:

common/config/main.php:

<?php
return [
    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
    'modules' => [
        'user' => [
            'class' => 'dektrium\user\Module',
            // you will configure your module inside this file
            // or if need different configuration for frontend and backend you may
            // configure in needed configs
        ],
    ],
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'authManager' => [
            'class' => 'yii\rbac\DbManager',
            'defaultRoles' => ['guest'],
        ],
    ],
];

frontend/config/main.php

    <?php
$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);

return [
    'id' => 'app-frontend',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'frontend\controllers',
    'modules' => [
        'user' => [
            // following line will restrict access to admin page
            'as frontend' => 'dektrium\user\filters\FrontendFilter',
        ],
    ],
    'components' => [
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ], 
    ],

    'params' => $params,
];

I'm new with yii2-user and rbac.

5

5 Answers

2
votes

You can use this command to run the migration:

php yii migrate/up --migrationPath=@vendor/dektrium/yii2-user/migrations
1
votes

You need to run yii migrate command.

1
votes

Since version 2.0.12 you may also specify an array of migration paths that should be searched for migrations to load.

in console config you could add:

'controllerMap' => [
    'migrate' => [
        'class' => MigrateController::class,
        'migrationPath' => [
            '@app/migrations',
            '@vendor/dektrium/yii2-user/migrations'
        ],
        'migrationNamespaces' => [
        ],
    ],
]

if you run the

php yii migrate/up

then @vendor/dektrium/yii2-user/migrations will be included all the time.

the advantage is that you will not run into an error if one of the updates comes with a migration

0
votes

You need to add a status column into your user table, just like below:

alter table user add status smallint(6) NOT NULL DEFAULT '10'

0
votes

It looks like you skipped third part of installing dektrium/yii2-user package. And that is applying migration that comes with the package. By runiing these migrations you ensure that in your database you will have tables needed for correct functionality of the package. Some of them is user table for example.

This is what you skipped from instalation guide:

3. Update database schema.

The last thing you need to do is updating your database schema by applying the migrations. Make sure that you have properly configured db application component and run the following command:

$ php yii migrate/up --migrationPath=@vendor/dektrium/yii2-user/migrations

Look here