传递给 yii\db\conditions\HashConditionBuilder::build() 的参数 2 必须是数组类型,Yii2 中给出的字符串

Argument 2 passed to yii\db\conditions\HashConditionBuilder::build() must be of the type array, string given in Yii2

当我尝试在两个表之间进行连接时出现错误。

这是我的控制器

public function actionView($id)
{
    $view = (new \yii\db\Query())
        ->select(['id', 'user_id', 'body', 'title'])
        ->join('INNER JOIN', 'users', 'blog.user_id','users.id')
        ->where(['blog.id' => $id])
        ->one();

    return $this->render('view', compact('view'));
}

这是我的观点

 <div class="col-lg-4">
            <h2><?= $view['name'] . ' ' . $view['surname'] ?></h2>
            <h3><?= $view['title']; ?></h3>
            <p><?= $view['body']; ?></p>
            <a href="<?php echo yii::$app->homeUrl; ?>" class="btn btn-default">Back </a>
            <?= Html::a('Delete', ['delete', 'id' => $view['id']], ['class' => 'btn btn-danger']) ?>
        </div>

在 prima vista 上,很明显您忘记了 QueryBuilderfrom 子句。

看看这个:

$view = (new \yii\db\Query())
        ->select(['id', 'user_id', 'body', 'title'])
        ->from('blog') // this is your from clause of the query
        ->join('INNER JOIN', 'users', 'blog.user_id = users.id')
        ->where(['blog.id' => $id])
        ->one();