I'm new in the Yii2 framework and I'm a bit confused where to put the code to present the QR. I'm trying to create a QR for every entry in my Yii2 advance template. This QR contains the information of the $id. I want the QR code to be generated when the user creates an entry and to present that QR in the view php
<?php
namespace backend\controllers;
use Yii;
use common\models\Weatherstation;
use common\models\WeatherstationSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
/**
- WeatherstationController implements the CRUD actions for Weatherstation model.
_/
class WeatherstationController extends Controller
{
/_*
- @inheritdoc
*/
public function behaviors()
{
return [
'access'=>[
'class'=>AccessControl::classname(),
'only'=>['create','update'],
'rules'=>[
[
'allow'=>true,
'roles'=>['@']
],
]
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
- Lists all Weatherstation models.
- @return mixed
*/
public function actionIndex()
{
$searchModel = new WeatherstationSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
- Displays a single Weatherstation model.
- @param integer $id
- @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
- Creates a new Weatherstation model.
- If creation is successful, the browser will be redirected to the 'view' page.
- @return mixed
*/
public function actionCreate()
{
$model = new Weatherstation();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
- Updates an existing Weatherstation model.
- If update is successful, the browser will be redirected to the 'view' page.
- @param integer $id
- @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
- Deletes an existing Weatherstation model.
- If deletion is successful, the browser will be redirected to the 'index' page.
- @param integer $id
- @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
- Finds the Weatherstation model based on its primary key value.
- If the model is not found, a 404 HTTP exception will be thrown.
- @param integer $id
- @return Weatherstation the loaded model
- @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Weatherstation::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
use barcode\barcode\BarcodeGenerator;
/\* @var $this yii\web\View _/
/_ @var $model common\models\Weatherstation */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Weatherstations', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="weatherstation-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
\
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'WeatherStation_Model',
'WeatherStation_Name',
'WeatherStation_Location',
'WeatherStation_Status',
'WeatherStation_Gateway',
'WeatherStation_Logger',
'WeatherStation_Number',
],
]) ?>
</div>