【问题标题】:Yii 2 Getting unknown property: common\models\User::newMessagesCountYii 2 获取未知属性:common\models\User::newMessagesCount
【发布时间】:2017-12-23 00:47:59
【问题描述】:

我正在尝试使用 Yii2 Podium 在我的网站中建立论坛。但是安装之后就进不去了

讲台/家

我收到了这条消息:

Unknown Property – yii\base\UnknownPropertyException
Getting unknown property: common\models\User::newMessagesCount

这是组件文件

在 C:\xampp\htdocs\tugasakhir\vendor\yiisoft\yii2\base\Component.php 中

public function __get($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        // read property, e.g. getName()
        return $this->$getter();
    }

    // behavior property
    $this->ensureBehaviors();
    foreach ($this->_behaviors as $behavior) {
        if ($behavior->canGetProperty($name)) {
            return $behavior->$name;
        }
    }

    if (method_exists($this, 'set' . $name)) {
        throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
    }

    throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
}

会有什么问题?

【问题讨论】:

  • 错误在User 模型在您的common/models 文件夹中它无法在表user 中找到字段名称,您必须运行带有计数的选择查询,newMessagesCount 是别名.是真的吗?
  • 更新您的问题并添加您的用户模型

标签: php yii


【解决方案1】:

您不必更改 \vendor\yiisoft\yii2\base\Component.php 中的任何内容,但您必须控制它们在 \models\user 中设置变量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-06
    • 2014-06-25
    相关资源
    最近更新 更多