下面是我在 UserSearch 模型的搜索功能中使用的 dataprovider 查询,从 User 模型扩展而来。我试图在网格视图中显示“条目”的值,但无法访问“条目”列。请帮忙。
$query = User::find()
->select("users.Id, users.FirstName, users.LastName, users.EntryId, GROUP_CONCAT(entry.EntryId ORDER BY entry.Id SEPARATOR '<br>') as entries")
->join('LEFT OUTER JOIN','entry','entry.CustomerEntryId = users.EntryId')
->where(['users.IsActive' =>1])
->groupBy('users.Id');
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
用户型号代码
class User extends \yii\db\ActiveRecord
{
public $password_repeat;
public static function tableName()
{
return 'users';
}
public function rules()
{
return [
[['FirstName','LastName','EmailId','MobileNo','Password','password_repeat'], 'required'],
['EmailId', 'email'],
[['EmailId'], 'unique'],
['password_repeat', 'compare', 'compareAttribute'=>'Password', 'message'=>"Passwords don't match", ],
['MobileNo', 'is8NumbersOnly'],
];
}
public function is8NumbersOnly($attribute)
{
if (!preg_match('/^[0-9]{8}$/', $this->$attribute)) {
$this->addError($attribute, 'must contain exactly 8 digits.');
}
}
}
网格视图代码
echo GridView::widget([
'dataProvider'=>$dataProvider,
'filterModel'=>$searchModel,
'showPageSummary'=>true,
'pjax'=>true,
'striped'=>true,
],
'panel'=>['type'=>'primary', 'heading'=>'Members Report'],
'columns' => [
[
'label'=>'First Name',
'attribute'=>'FirstName',
'value'=>'FirstName',
],
[
'label'=>'Email Id',
'attribute'=>'EmailId',
'value'=>'EmailId',
],
[
'label'=>'Entries',
'attribute'=>'Entries',
'value'=>'entries',
],
],
]);