2017-03-06 74 views
2

我已經使用gii工具來創建crud應用程序。我有3桌'Empreendy','Tramity','Protoprocess'。 gridview工作正常,顯示所有必要的數據,但是搜索字段'nomeempreend'沒有出現。Yii2字段過濾器沒有在GridView上顯示與3表相關

[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]); 

====公共$ empreendiment;

==== /** * @返回\警予\ DB \ ActiveQuery */ 公共職能getOrgars(){ 回報 $這個 - > 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'], 
    ] 
} 

讓我知道,如果你的作品,就像是我的作品!