php - relational access in yii2 -
i want join 2 tables in yii 2 have relation each other. example have model named digital
, model named tablet
relation digital model foreign key sup_id
.
so wanna access , show of these 2 tables entities in listview
. when use join tag access model call in model::find()
!!!! want of them :( shows
getting unknown property: app\models\digital::sim_num
for example. defined relations in model
here action in sitecontroller
public function actionpagination_product2(){ $dataprovider = new activedataprovider([ 'query' => digital::find()->select("digital.*")->leftjoin('tablet','tablet.sup_id= digital.id'), 'pagination' => [ 'pagesize' => 20, ], ]); return $this->render('pagination_pro2', [ 'dataprovider' => $dataprovider, ]); }
and in views/site/pagination_pro2 have
use yii\widgets\listview; echo listview::widget([ 'dataprovider' => $dataprovider, 'itemview' => '_page1', ]);
and in views/site/_page1 have
<?php use yii\helpers\html; use yii\helpers\htmlpurifier; ?> <div class = "user"> <?= $model->sim_num?> </div>
where problem ?:((
it good, if define relation in digital
model like
public function gettablet() { return $this->hasone(tablet::class, ['id' => 'sup_id']); }
you don't have join in query
passed dataprovider
if don't use in query. access in view file, use:
$model->tablet->sim_num;
Comments
Post a Comment