[英]Argument 2 passed to yii\db\conditions\HashConditionBuilder::build() must be of the type array, string given in Yii2
當我試圖在兩個表之間進行連接時,我得到了錯誤。
這是我的 controller
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 上,很明顯您忘記了QueryBuilder
的from
子句。
看看這個:
$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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.