在高级模板中配置yii2-module时出现以下错误:
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}
我已按照这些说明操作:
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
与作曲家一起安装:
composer require "dektrium/yii2-user:0.9.*@dev"
并编辑了所需的文件:
公共/配置/ 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'],
],
],
];
前端/配置/ 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,
];
我是yii2-user和rbac的新手。
答案 0 :(得分:2)
您可以使用此命令运行迁移:
php yii migrate/up --migrationPath=@vendor/dektrium/yii2-user/migrations
答案 1 :(得分:1)
您需要运行yii migrate
命令。
答案 2 :(得分:1)
从 2.0.12 版开始,您还可以指定一组迁移路径,应搜索这些路径以加载要加载的迁移。
在控制台配置中,您可以添加:
'controllerMap' => [
'migrate' => [
'class' => MigrateController::class,
'migrationPath' => [
'@app/migrations',
'@vendor/dektrium/yii2-user/migrations'
],
'migrationNamespaces' => [
],
],
]
如果你运行
php yii 迁移/向上
那么@vendor/dektrium/yii2-user/migrations 将一直包含在内。
优点是,如果其中一个更新伴随着迁移,您不会遇到错误
答案 3 :(得分:0)
您需要在用户表中添加状态列,如下所示:
alter table user add
status
smallint(6)NOT NULL DEFAULT'10'
答案 4 :(得分:0)
您似乎跳过了安装dektrium/yii2-user
软件包的第三部分。这就是应用程序包附带的迁移。通过运行这些迁移,您可以确保在数据库中拥有正确使用软件包功能所需的表。其中有些是user
表。
这是您从安装指南中跳过的内容:
3。更新数据库架构。
您需要做的最后一件事是通过应用迁移来更新数据库架构。确保您已正确配置数据库应用程序组件并运行以下命令:
$ php yii migration / up --migrationPath = @ vendor / dektrium / yii2-user / migrations
看here