2
votes

I have used the gii tool to create crud application. I have 3 tables 'Empreendy' , 'Tramity', 'Protoprocess'. The gridview is working perfectly, showing all the necessary data, however the search field 'nomeempreend' not appeared.

[Protoprocess table]

id (*)      |  int
============|=======
codprocesso |  char
============|=======
empreendy_id|  int
============|=======
dtabertura  |  date

[Tramity table]

id (*)         |  int
===============|=======
protoprocess_id|  int
===============|=======
datacad        |  date

[Empreendy Table]

id (*)       |  int
=============|=======
clientesy_id |  char
=============|=======
empreendy_id |  int
=============|=======
address      |  char

Index fail

 <?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
       // 'protoprocess_id',
// #update here  < ####
     [
           'attribute' => 'empreendiment',
       'label'=>'Empreendimento',
       'value' => 'empreendyName.empreendy.nomeempreend',
           'filter'=>ArrayHelper::map(Empreendy::find()->asArray()->all(), 'id', 'nomeempreend'),
        ],

// # end here < ####

[
            'attribute' => 'protoprocess_id',
            'value'    => 'protoprocess.codprocesso',
        ],

=======

class TramitySearch extends Tramity
{
/**
 * @inheritdoc
 */

public $empreendy_id;
public function rules()
{
    return [
        [['id'], 'integer'],
        [['obs', 'orgars_id', 'datacad', 'statusproto', 'protoprocess_id', 'empreendy_id', 'Dbusers_id'], 'safe'],
    ];
}


 public function search($params)
{
    $query = Tramity::find();

    // add conditions that should always apply here

    $dataProvider = new ActiveDataProvider([
        'query' => $query,
    ]);

    $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->joinWith('orgars');
$query->joinWith('protoprocess');
$query->joinWith('empreendyName');
    // grid filtering conditions
    $query->andFilterWhere([
        'id' => $this->id,
     //   'protoprocess_id' => $this->protoprocess_id,
     //   'orgars_id' => $this->orgars_id,
        'datacad' => $this->datacad,
   'empreendyName.empreendy.nomeempreend' => $this->empreendy_id,

  //        'Dbusers_id' => $this->Dbusers_id,
    ]);

    $query->andFilterWhere(['like', 'obs', $this->obs])
        ->andFilterWhere(['like', 'statusproto', $this->statusproto])
        ->andFilterWhere(['like', 'codprocesso', $this->protoprocess_id])
        //    ->andFilterWhere(['like',  'nomeempreend', $this->empreendy_id])
          ->andFilterWhere(['like', 'sigla', $this->orgars_id]);

==== public $empreendiment;

==== /** * @return \yii\db\ActiveQuery */ public function getOrgars() { return $this->hasOne(Orgars::className(), ['id' => 'orgars_id']); }

 /**
 * @return \yii\db\ActiveQuery
 */
  public function getProtoprocess()
{
    return $this->hasOne(Protoprocess::className(), ['id' => 'protoprocess_id'])->with(['empreendy']);
}

public function getDbusers()
{
    return $this->hasOne(Dbusers::className(), ['id' => 'Dbusers_id']);
}

public function getDeptoOrgars()
{
    return $this->hasMany(DeptoOrgars::className(), ['orgars_id' => 'id']);
}

public function getSeqTramity()
{
    return $this->hasMany(SeqTramity::className(), ['tramity_id' => 'id']);
} 



public function getEmpreendyName()
{
return $this->hasOne(Protoprocess::className(), ['id' => 'protoprocess_id'])->with(['tramity']);
}

=====

How to proceed for the input to be shown in the query by 'nomeempreend'?

1
Same problem here!Maykonn

1 Answers

-1
votes

Only fields in rules() are searchable, thus:

On your TramitySearch class

public function rules()
{
    return [
        [['protoprocess.empreendy_id'], 'integer'],
        [['protoprocess_id'], 'integer'],
    ]
}

Let me know if works for you, like works for me!