Skip to main content

Notes

 

Useful extensions

https://wbraganca.com/yii2extensions

Sorting/filtering in model met relaties

https://www.yiiframework.com/wiki/653/displaying-sorting-and-filtering-model-relations-on-a-gridview

Bootstrap (4) Icons

https://www.w3schools.com/icons/bootstrap_icons_glyphicons.asp

Active Records

In Controller, get data from arbitrary model;

use app\models\Examen;

$examen = examen::find()->where(['actief' => '1'])->orderBy(['datum_van' => 'SORT_DESC'])->one();

$examen = examen::find()->where(['actief' => '1'])->orderBy(['datum_van' => 'SORT_DESC'])->all();

$gesprekSoort = gesprekSoort::find()->all();

$gesprekSoort = examenGesprekSoort::findAll(['examen_id' => $id]);

$sql="delete from examen_gesprek_soort where examen_id = :examenid";
$params = array(':examenid'=> $id);
Yii::$app->db->createCommand($sql)->bindValues($params)->execute();

$sql="insert into examen_gesprek_soort (examen_id, gesprek_soort_id) values(:examenid, :gesprekid)";
$params = array(':examenid'=> $id, ':gesprekid' => $value );
Yii::$app->db->createCommand($sql)->bindValues($params)->execute();

$gesprekken = gesprekSoort::find()->where([])->joinWith('examenGesprekSoorts')->all();

Debug

https://www.yiiframework.com/wiki/793/debuging-variables-in-yii2

Voor- nadelen

  Laravel YII
MVC
Model Eloquent Active Record
View/templating Blade PHP met 'Yii Snippets'
Routing Expliciet Impliciet / Expliciet
Migrations
(meer als optie)
Model creations command line
GUI, reverse engineered form DB
Controller Creation command line
GUI, create full CRUD
View creation ?
GUI, create full CRUD
Documentation ***
**
Active development
Add Ons / Libraries *** **
Install Base (volgens Google) 484,970 58,800
     

Grootste voordeel is de GUI waarmee je reverse engineered een CRUD maakt.

Login

http://code-epicenter.com/how-to-login-user-from-a-database-in-yii-framework-2/

 

Create CRUD Example

Model Class app\models\Examen
Search Model Class app\models\ExamenSearch
Controller Class app\controllers\ExamenController
View path leeg laten (wordt default waaarde)

Datepicker Install

(in project root)

change in file composer.dev  "minimum-stability": "dev",

 

Bootstrap 4 install

composer require --prefer-dist yiisoft/yii2-bootstrap4
<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        // ['class' => 'yii\grid\SerialColumn'],
        [
          'attribute'=>'naam',
          'contentOptions' => ['style' => 'width:600px; white-space: normal;'],
          'format' => 'raw',
          'value' => function ($data) {
            return Html::a($data->naam, '/examen/update?id='.$data->id);
          },
        ],
        [
          'attribute'=>'datum_van',
          'contentOptions' => ['style' => 'width:40px; white-space: normal;'],
        ],
    ],
]); ?>

Save, Delete en Cancel Button

// Save
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>

// Delete
<a class="btn btn-danger" href="/gesprek/delete?id=<?=$model->id?>" data-confirm="Gesprek verwijderen?" data-method="post">Delete</a>

// Cancel
<?= Html::a('Cancel', ['/gesprek/overzicht'], ['class'=>'btn btn-primary']) ?>

Redirect

return $this->redirect(['view', 'id' => $model->id]);