mysql - Yii2 : Model returning NULL value (not set) when using Widget Detail VIew -
i want ask using detailview widget. want show data join table, modified function findmodel($id) :
protected function findmodel($id) {     if (($model = tpq::findone($id)) !== null) {         $data = $model::findbysql("select * tpq, kurikulum, pengurus tpq.kurikulum_id = kurikulum.kurikulum_id , tpq.pengurus_id = pengurus.pengurus_id , tpq_id = $id")->all();         return $data;     } else {         throw new notfoundhttpexception('the requested page not exist.');     } }   i use function in view
   public function actionview($id)     {         return $this->render('view', [             'model' => $this->findmodel($id),         ]);     }   my view :
<?= detailview::widget([     'model' => $model,     'attributes' => [         'tpq_id',         'tpq_nama',         'tpq_alamat',         'tpq_koordinat',         'tpq_berdiri',         'tpq_aktif',         'kurikulum_nama',         'kurikulum_detail:ntext',         'kurikulum_aktif',         'pengurus_nama',         'pengurus_alamat',         'pengurus_nohp',     ], ]) ?>   fields in table tpq : 'tpq_id', 'kurikulum_id', 'pengurus_id', 'tpq_nama', 'tpq_alamat', 'tpq_koordinat', 'tpq_berdiri', 'tpq_aktif'
fields in table pengurus : 'pengurus_id','user_id','pengurus_nama','pengurus_alamat','pengurus_nohp'
fields in table kurikulum : 'kurikulum_id', 'kurikulum_nama', 'kurikulum_detail', 'kurikulum_aktif'
there no error, shows 'not set' value. how fix it?
there problems code.
1) use english naming because it's international language. think other developers may support code , don't know language.
2) it's better replace findbysql() activequery methods. why activerecord needed if don't use features? don't see complex logic in query, , complex logic can built activequery.
3) multiple tables need specify relations or display multiple detailview widgets instead. widget designed work 1 model.
4) displaying relations can use dot notation or getters.
example dot notation:
'relation.attributename',   example getter:
[     'attribute' => 'attributename',     'value' => $model->relation->attributename, ],   read official docs more details.
Comments
Post a Comment