Yii Framework 自定义搜索模型报错
Error in customizing Search Model in Yii Framework
我对 Yii 非常陌生并创建了一个处理 Users 和 Groups[的 Web 应用程序=43=] 使用 Yii 高级应用程序框架。
目前我已经使用 gii 工具完成了所有数据库部分和创建模型以及 CRUD 操作。
这是我的相关数据库 (user_group.group_owner_id ----> user.id
)
问题:
当我导航到用户组页面时,它会显示所有用户的所有组。
但我只想显示他创建的组。
所以我自定义了UserGroupSearch
模型如下,但是它抛出了一个语法错误。
UserGroupSearch.php
public function search($params)
{
$current_logged_user_id = Yii::$app->user->identity->id; //get the id of the current user
$query = UserGroup::find()->where(['group_owner_id' = $current_logged_user_id]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
//other codes
}
错误:
PHP Parse Error – yii\base\ErrorException
syntax error, unexpected '=', expecting ']'
错误行号显示为带有 where clause
的行
where(['group_owner_id' = $current_logged_user_id])
需要更改为
where(['group_owner_id' => $current_logged_user_id])
我对 Yii 非常陌生并创建了一个处理 Users 和 Groups[的 Web 应用程序=43=] 使用 Yii 高级应用程序框架。
目前我已经使用 gii 工具完成了所有数据库部分和创建模型以及 CRUD 操作。
这是我的相关数据库 (user_group.group_owner_id ----> user.id
)
问题:
当我导航到用户组页面时,它会显示所有用户的所有组。
但我只想显示他创建的组。
所以我自定义了UserGroupSearch
模型如下,但是它抛出了一个语法错误。
UserGroupSearch.php
public function search($params)
{
$current_logged_user_id = Yii::$app->user->identity->id; //get the id of the current user
$query = UserGroup::find()->where(['group_owner_id' = $current_logged_user_id]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
//other codes
}
错误:
PHP Parse Error – yii\base\ErrorException
syntax error, unexpected '=', expecting ']'
错误行号显示为带有 where clause
where(['group_owner_id' = $current_logged_user_id])
需要更改为
where(['group_owner_id' => $current_logged_user_id])