2017-03-06 8 views
2

私はgiiツールを使用してcrudアプリケーションを作成しました。私は3つのテーブル 'Empreendy'、 'Tramity'、 'Protoprocess'を持っています。 gridviewは完全に動作していますが、必要なすべてのデータが表示されますが、検索フィールド 'nomeempreend'は表示されません。Yii2フィールドフィルタが3つのテーブルを持つGridViewに表示されない

[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'), 
     ], 

//#ここで終わり< ####

[ 
      '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 */ パブリック関数getOrgars(){ 戻ります$ this-> hasOneの(Orgars ::クラス名()、[」 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']); 
} 

=====

入力が 'nomeempreend' でクエリに示すことが進行するには?

+0

ここに同じ問題があります。 – Maykonn

答えて

0

ルールでのみのフィールドは()ので、検索可能です:あなたTramitySearchクラスで

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

は私のための作品のようなあなたのために働き、なら、私を知ってみましょう!

関連する問題