Skip to main content

Notes

(persoonlijk aantekeningen; moet nog worden uitgewerkt)

Useful extensions

https://wbraganca.com/yii2extensions

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/

N:M relation

https://forum.yiiframework.com/t/please-explain-how-to-do-many-to-many-relationships-for-newcomer/29743/3

 

-- TEMP ---

Gebruik gii om je models en standaard CRUS's te maken.

Create CRUD

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 composer.dev  "minimum-stability": "dev",

composer require "nex/yii2-datepicker"

-- TEMP ---

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

Bootstrap 4

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;'],
        ],
    ],
]); ?>

 

 

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