hello everyone, i have a problem i tried to make a gridView with relational data, although this is shown, but this is not filtered or sorted. I followed the instructions given me the definitive guide from this page, but i don’t know what i’m really doing wrong.
Search Model
<?php
namespace backend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\Usuario;
/**
* UsuariosBuscar represents the model behind the search form about `app\models\Usuario`.
*/
class UsuariosBuscar extends Usuario
{
/**
* @inheritdoc
*/
public $persona;
public function rules()
{
return [
[['clvcodigo', 'clvpersona'], 'integer'],
[['strusername', 'strpassword', 'strstatus', 'strpassword_reset_token', 'persona'], 'safe'],
[['blnborrado'], 'boolean'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Usuario::find();
$query->joinWith(['persona']);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$dataProvider->sort->attributes['persona'] = [
'asc' => ['tblpersona.strnombres' => SORT_ASC],
'desc' => ['tblpersona.strnombres' => SORT_DESC]
];
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'clvcodigo' => $this->clvcodigo,
'clvpersona' => $this->clvpersona,
'blnborrado' => $this->blnborrado,
]);
$query->andFilterWhere(['like', 'strusername', $this->strusername])
->andFilterWhere(['like', 'strpassword', $this->strpassword])
->andFilterWhere(['like', 'strstatus', $this->strstatus])
->andFilterWhere(['like', 'strpassword_reset_token', $this->strpassword_reset_token])
->andFilterWhere(['like', 'tblpersona.strnombres', $this->persona]);
return $dataProvider;
}
}
Controller
public function actionIndex()
{
$searchModel = new UsuariosBuscar();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
GridView
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'strusername',
['attribute' => 'Persona',
'value' => 'persona.strnombres'],
'strstatus',
//'getClvpersona0' => $this->getClvpersona0->strnombres,
// 'strpassword_reset_token',
// 'blnborrado:boolean',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
thanks for the help you can give me…