php - there is no any change to the rows displayed when doing "search" in yii2 -


i have problem when making modelsearch in yii2. here's relation diagram

enter image description here

i want display jurusan table aitambah table ais3 , want display namamahasiswa table ai ais3. made table s3penghubung table aitambah can related ais3. able display them. but, when try type "bio" in jurusan field, searching not working properly. refreshing page. there no change rows displayed. so, should fix that? enter image description here

model search code

<?php  namespace app\models;  use yii; use yii\base\model; use yii\data\activedataprovider; use app\models\ais3; use app\models\aitambah;  /**  * ais3search represents model behind search form `app\models\ais3`.  */ class ais3search extends ais3 {     /**      * @inheritdoc      */     public function rules()     {         return [             [['id', 'kode'], 'integer'],             [['nrp', 'nrp1', 'nrp2', 'nrp3', 'nrp4', 'nrp5', 'nrp6', 'nrp7', 'namamahasiswatext', 'programstudi', 'tanggalmasuk', 'tanggalkeluar', 'jurusantext','namkantor','angkatan'], 'safe'],         ];     }      public $namamahasiswa;     public $namamahasiswatext;     public $nrp1;     public $nrp2;     public $nrp3;     public $nrp4;     public $nrp5;     public $nrp6;     public $nrp7;     public $jurusan;     public $jurusantext;     public $namkantor;     public $angkatan;          /**      * @inheritdoc      */     public function scenarios()     {         // bypass scenarios() implementation in parent class         return model::scenarios();     }      /**      * creates data provider instance search query applied      *      * @param array $params      *      * @return activedataprovider      */     public function search($params)     {         $query = ais3::find();         $query->joinwith('ai');          // add conditions should apply here          $dataprovider = new activedataprovider([             'query' => $query,         ]);          $this->load($params);          if (!$this->validate()) {             // uncomment following line if not want return records when validation fails             // $query->where('0=1');             return $dataprovider;         }          // grid filtering conditions         $query->andfilterwhere([             'id' => $this->id,             'kode' => $this->kode,          ]);             $query->andfilterwhere(['like', 'ais3.nrp', $this->nrp])             ->andfilterwhere(['like', 'ai.namamahasiswa', $this->namamahasiswatext])             ->andfilterwhere(['like', 'ais3.programstudi', $this->programstudi])             ->andfilterwhere(['like', 'ai.tanggalmasuk', $this->tanggalmasuk])             ->andfilterwhere(['like', 'ais3.tanggalkeluar', $this->tanggalkeluar])             ->andfilterwhere(['like', 'aitambah.jurusan', $this->jurusan]);            return $dataprovider;     } } 

my gridview code

    <?= gridview::widget([         'dataprovider' => $dataprovider,         'filtermodel' => $searchmodel,         'columns' => [             ['class' => 'yii\grid\serialcolumn'],              //'id',             'nrp',             'namamahasiswatext',             'programstudi',             //'tanggalmasuk',             [             'attribute' => 'tanggalmasuk',             'value' => function($data) {                 return $data->ai->tanggalmasuk;             },],             'tanggalkeluar',              //yang ditambah             /*[                 'attribute'=>'nrp1',                 'value'=>'s3penghubung.aitambah.jurusan',                 'label' => 'jurusan',             ],*/              'jurusantext',              [                 'attribute'=>'nrp2',                 'value'=>'s3penghubung.aitambah.namkantor',                 'label' => 'nama kantor',             ],             [                 'attribute'=>'nrp3',                 'value'=>'s3penghubung.aitambah.angkatan',                 'label' => 'angkatan',             ],             [                 'attribute'=>'nrp4',                 'value'=>'s3penghubung.aitambah.telp',                 'label' => 'nomor hp/telp',             ],             [                 'attribute'=>'nrp5',                 'value'=>'s3penghubung.aitambah.pekerjaan',                 'label' => 'pekejaan',             ],             [                 'attribute'=>'nrp6',                 'value'=>'s3penghubung.aitambah.email',                 'label' => 'email',             ],             [                 'attribute'=>'nrp7',                 'value'=>'s3penghubung.aitambah.kodeprop',                 'label' => 'kodeprop',             ],               // 'kode',              ['class' => 'yii\grid\actioncolumn'],         ],     ]); ?> 

my model's code

<?php  namespace app\models;  use yii;  /**  * model class table "ais3".  *  * @property integer $id  * @property string $nrp  * @property string $programstudi  * @property string $tanggalmasuk  * @property string $tanggalkeluar  * @property integer $kode  *  * @property ai $nrp  * @property s3penghubung $kode0  */ class ais3 extends \yii\db\activerecord {     /**      * @inheritdoc      */     public static function tablename()     {         return 'ais3';     }      /**      * @inheritdoc      */     public function rules()     {         return [             [['kode'], 'required'],             [['kode'], 'integer'],             [['nrp'], 'string', 'max' => 15],             [['programstudi'], 'string', 'max' => 5],             [['tanggalmasuk', 'tanggalkeluar'], 'string', 'max' => 20],             [['nrp'], 'exist', 'skiponerror' => true, 'targetclass' => ai::classname(), 'targetattribute' => ['nrp' => 'nrp']],             [['kode'], 'exist', 'skiponerror' => true, 'targetclass' => s3penghubung::classname(), 'targetattribute' => ['kode' => 'kode']],         ];     }      /**      * @inheritdoc      */     public function attributelabels()     {         return [             'id' => yii::t('app', 'id'),             'nrp' => yii::t('app', 'nrp'),             'programstudi' => yii::t('app', 'program studi'),             'tanggalmasuk' => yii::t('app', 'tanggal masuk'),             'tanggalkeluar' => yii::t('app', 'tanggal keluar'),             'kode' => yii::t('app', 'kode'),             'namamahasiswatext' => yii::t('app', 'nama mahasiswa'),             'jurusantext' => yii::t('app', 'jurusan'),         ];     }      /**      * @return \yii\db\activequery      */     public function getai()     {         return $this->hasone(ai::classname(), ['nrp' => 'nrp']);     }        /**      * @return \yii\db\activequery      */     public function gets3penghubung()     {         return $this->hasone(s3penghubung::classname(), ['kode' => 'kode']);     }      //yang ditambah     public function getrelasis3()     {         return array(                 'aitambah'=>array(self::many_many, 'aitambah', 's3penghubung(ais3.id, aitambah.nrp)'),             );     }       public function getnamamahasiswatext()     {         $ai = ai::findone(['nrp'=> $this->nrp]);         if (empty($ai))             return '';         return $ai->namamahasiswa;     }      public function getjurusantext()     {         $aitambah = aitambah::findone(['nrp'=> $this->nrp]);         if (empty($aitambah))             return '';         return $aitambah->jurusan;     }  } 

i dont know how fix codes. please me solve this? thankyou

your code difficult debug. try keep consistency naming conventions. yii way lower case letters separated underscores.

please read this , this displaying , sorting relations.

as solution can experiment bit following:


create new relation in model:

/**  * @return \yii\db\activequery  */ public function getaitambah() {     return $this->hasone(aitambah::classname(), ['nrp' => 'nrp']); } 

then in searchmodel:

public function rules() {     return [         [['id', 'kode'], 'integer'],         [['nrp', 'nrp1', 'nrp2', 'nrp3', 'nrp4', 'nrp5', 'nrp6', 'nrp7', 'namamahasiswatext', 'programstudi', 'tanggalmasuk', 'tanggalkeluar', 'jurusantext','namkantor','angkatan', 'jurusan'], 'safe'],     ]; } 

and in search method:

... $query = ais3::find(); query->joinwith(['ai ai', 'aitambah aitambah']); ... 

finally in view:

[     'attribute' => 'jurusan',     'value' => 'aitambah.jurusan',     'label' => 'jurusan', ], 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -