1. Go to this page and download the library: Download kartik-v/yii2-widgets library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kartik-v / yii2-widgets example snippets
// add this in your view
use kartik\widgets\ActiveForm;
$form = ActiveForm::begin();
use kartik\widgets\FileInput;
// Usage with ActiveForm and model
echo $form->field($model, 'avatar')->widget(FileInput::classname(), [
'options' => ['accept' => 'image/*'],
]);
// With model & without ActiveForm
echo '<label class="control-label">Add Attachments</label>';
echo FileInput::widget([
'model' => $model,
'attribute' => 'attachment_1',
'options' => ['multiple' => true]
]);
use kartik\widgets\ColorInput;
// Usage with ActiveForm and model
echo $form->field($model, 'color')->widget(ColorInput::classname(), [
'options' => ['placeholder' => 'Select color ...'],
]);
// With model & without ActiveForm
echo '<label class="control-label">Select Color</label>';
echo ColorInput::widget([
'model' => $model,
'attribute' => 'saturation',
]);
use kartik\widgets\RangeInput;
// Usage with ActiveForm and model
echo $form->field($model, 'rating')->widget(RangeInput::classname(), [
'options' => ['placeholder' => 'Select color ...'],
'html5Options' => ['min'=>0, 'max'=>1, 'step'=>1],
'addon' => ['append'=>['content'=>'star']]
]);
// With model & without ActiveForm
echo '<label class="control-label">Adjust Contrast</label>';
echo RangeInput::widget([
'model' => $model,
'attribute' => 'contrast',
'addon' => ['append'=>['content'=>'%']]
]);
use kartik\widgets\SwitchInput;
// Usage with ActiveForm and model
echo $form->field($model, 'status')->widget(SwitchInput::classname(), [
'type' => SwitchInput::CHECKBOX
]);
// With model & without ActiveForm
echo SwitchInput::widget([
'name' => 'status_1',
'type' => SwitchInput::RADIO
]);
use kartik\widgets\StarRating;
// Usage with ActiveForm and model
echo $form->field($model, 'rating')->widget(StarRating::classname(), [
'pluginOptions' => ['size'=>'lg']
]);
// With model & without ActiveForm
echo StarRating::widget([
'name' => 'rating_1',
'pluginOptions' => ['disabled'=>true, 'showClear'=>false]
]);