Table of Contents

Yii PHP Framework

Homepage

Gii

Gii can generate models for you. If you want to generate a model for all database tables, enter * for the database name.

useful extensions

widgets

useful helpers

Snippets

Select2 with values from DB table

<?php
use yii\helpers\ArrayHelper;
use kartik\select2\Select2;
use app\models\YourModelYouWantToQuery;
?>
 
…
 
    <?= $form->field($model, 'servicelevel_id')->widget(Select2::classname(), [
		'data' => ArrayHelper::map(YourModelYouWantToQuery::find()->all(),'servicelevel_id','servicelevel_id'),
		'options' => ['placeholder' => 'Select a service level …'],
		'pluginOptions' => [
			'allowClear' => true
		],
	]) ?>

input type with Html helper class

<?= Html::activeInput('number', $model, 'attribute', ['class' => 'form-control small-width', 'step' => '0.1', 'min' => '0', 'value' => $value]) ?>

always copy current vendor asset files in public dir

AssetBundle
/**
* @var array
*/
public $publishOptions = [
'forceCopy' => true
];

further reading

Documentation / Tutorials