Trying to fetch data from db
in controllers
$model = new CreateBookings();
$data = CreateBookings::model()->findByPk();
return $this->render('view', [
'data' => $data,
]);
in view :
<?php echo $data->booking_id?>
can somebody tell me what am i doing wrong?
The alternative for Yii1 findByPk
in Yii2 is findOne($id)
$model = CreateBookings::findOne($id);
or the equivalent
$model = CreateBookings::find()
->where(['id' => $id])
->one();
for your view you can use
$data = CreateBookings::findOne($id)) ;
and you should have the $id value.
Answering My own question:
I wanted to show database values in my View.
In controller actionView
I added-
$data = CreateBookings::findOne($id);
and rendered
'data' => $data,
To show value in view I used
<?php echo Html::encode($data->booking_id);?>