首页 文章

Yii2字段过滤器未显示在GridView上,与3个表相关

提问于
浏览
2

我用gii工具创建了crud应用程序 . 我有3张 table 'Empreendy','Tramity','Protoprocess' . gridview工作正常,显示所有必要的数据,但搜索字段'nomeempreend'没有出现 .

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

=====

如何通过'nomeempreend'继续输入查询?

1 回答

  • 0

    只有rules()中的字段是可搜索的,因此:

    On your TramitySearch class

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

    让我知道是否适合你,就像为我工作!

相关问题