1
下面是我在用戶模型擴展的UserSearch模型的搜索功能中使用的數據提供者查詢。我試圖在gridview中顯示'entries'的值,但無法訪問'entries'列。請幫忙。In Yii2無法在gridview中顯示模型中的自定義列
$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.');
}
}
}
GridView控件代碼
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',
],
],
]);
節目還您GridView的代碼..和用戶模型 – scaisEdge