yii \ base \ UnknownPropertyException:设置未知属性:cinghie \ articles \ Articles :: 0

时间:2018-12-08 18:09:04

标签: yii2

早上好, 试图安装此扩展 https://github.com/cinghie/yii2-articles

我收到这样的错误,该如何解决?

yii\base\UnknownPropertyException: Setting unknown property: cinghie\articles\Articles::0 in** /var/www/html/basic/vendor/yiisoft/yii2/base/Component.php:209
Stack trace:
#0 /var/www/html/basic/vendor/yiisoft/yii2/BaseYii.php(546): yii\base\Component->__set('0', Array)
#1 /var/www/html/basic/vendor/yiisoft/yii2/base/BaseObject.php(107): yii\BaseYii::configure(Object(cinghie\articles\Articles), Array)
#2 /var/www/html/basic/vendor/yiisoft/yii2/base/Module.php(158): yii\base\BaseObject->__construct(Array)
#3 [internal function]: yii\base\Module->__construct('articles', Object(yii\web\Application), Array)
#4 /var/www/html/basic/vendor/yiisoft/yii2/di/Container.php(384): ReflectionClass->newInstanceArgs(Array)
#5 /var/www/html/basic/vendor/yiisoft/yii2/di/Container.php(156): yii\di\Container->build('cinghie\\article...', Array, Array)
#6 /var/www/html/basic/vendor/yiisoft/yii2/BaseYii.php(349): yii\di\Container->get('cinghie\\article...', Array, Array)
#7 /var/www/html/basic/vendor/yiisoft/yii2/base/Module.php(427): yii\BaseYii::createObject(Array, Array)
#8 /var/www/html/basic/vendor/yiisoft/yii2/base/Module.php(586): yii\base\Module->getModule('articles')
#9 /var/www/html/basic/vendor/yiisoft/yii2/base/Module.php(522): yii\base\Module->createController('categories')
#10 /var/www/html/basic/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('articles/catego...', Array)
#11 /var/www/html/basic/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#12 /var/www/html/basic/web/index.php(12): yii\base\Application->run()
#13 {main}

也许原因是根据说明,您需要使用表前缀覆盖PREFIX_。我是这样的:

SQL查询:

INSERT INTO `auth_assignment` (` item_name`, `user_id`,` created_at`) VALUES
('admin', '1', 1451514052);

在SQL查询产生以下内容之后

MySQL响应:

  

#1452-无法添加或更新子行:外键约束   失败(ubuntuauth_assignment,约束auth_assignment_ibfk_1   删除时的外键(item_name)参考auth_itemname)   级联更新)

更新

已执行SQL查询,添加了admin id = 1条目,但错误仍然相同:

  

设置未知属性:cinghie \ Articles \ Articles :: 0

可能是因为从7迁移了3次失败:

output from console

1 个答案:

答案 0 :(得分:0)

在您将角色分配给用户之前,您似乎还没有添加admin角色,请确保您在admin表中添加了auth_item角色作为外键约束错误指的是,应该在

下面有一个条目
+-------+------+-------------+-----------+------+------------+------------+
| name  | type | description | rule_name | data | created_at | updated_at |
+-------+------+-------------+-----------+------+------------+------------+
| admin |    1 | NULL        | NULL      | NULL | 1525039496 | 1525039496 |
+-------+------+-------------+-----------+------+------------+------------+
1 row in set (0.00 sec)

否则,请运行以下查询

INSERT INTO `auth_item` (`name`, `type`) VALUES
('admin', 1);

现在运行扩展所需的查询,它将正常运行。

INSERT INTO `auth_assignment` (` item_name`, `user_id`,` created_at`) VALUES
('admin', '1', 1451514052);

更新

由于您在id = 1表中没有user用户,因此迁移失败,请参阅外键引发的错误。

  

异常:SQLSTATE [23000]:违反完整性约束:1452   无法添加或更新子行:外键约束失败   ({ubuntuarticle_items,约束fk_article_items_user_id   外键(user_id)参考userid)开启删除设置NULL开启   更新级联)

,并且所插入的SQL的ID为1,插入的ID为user_id,因此您应确保用户具有相同的id