PHP code example of kartik-v / yii2-builder
1. Go to this page and download the library: Download kartik-v/yii2-builder 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-builder example snippets
'modules' => [
'gridview' => [
'class' => '\kartik\grid\Module'
]
];
$query = Model::find()->indexBy('id'); // where `id` is your primary key
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
'attributes'=>[
'id'=>[ // primary key attribute
'type'=>TabularForm::INPUT_HIDDEN,
'columnOptions'=>['hidden'=>true]
],
]
use kartik\builder\Form;
$form = ActiveForm::begin();
echo Form::widget([
'model' => $model,
'form' => $form,
'columns' => 2,
'attributes' => [
'username' => ['type'=>Form::INPUT_TEXT, 'options'=>['placeholder'=>'Enter username...']],
'password' => ['type'=>Form::INPUT_PASSWORD, 'options'=>['placeholder'=>'Enter password...']],
'rememberMe' => ['type'=>Form::INPUT_CHECKBOX],
]
]);
ActiveForm::end();
use kartik\builder\Form;
use kartik\builder\FormGrid;
$form = ActiveForm::begin();
echo FormGrid::widget([
'model' => $model,
'form' => $form,
'autoGenerateColumns' => true,
'rows' => [
[
'attributes' => [
'username' => ['type'=>Form::INPUT_TEXT, 'options'=>['placeholder'=>'Enter username...']],
'password' => ['type'=>Form::INPUT_PASSWORD, 'options'=>['placeholder'=>'Enter password...']],
'rememberMe' => ['type'=>Form::INPUT_CHECKBOX],
],
],
[
'attributes' => [
'first_name' => ['type'=>Form::INPUT_TEXT, 'options'=>['placeholder'=>'Enter first name...']],
'last_name' => ['type'=>Form::INPUT_TEXT, 'options'=>['placeholder'=>'Enter last name...']],
]
]
]
]);
ActiveForm::end();
use kartik\builder\TabularForm;
$form = ActiveForm::begin();
echo TabularForm::widget([
'bsVersion' => '4.x',
'form' => $form,
'dataProvider' => $dataProvider,
'attributes' => [
'name' => ['type' => TabularForm::INPUT_TEXT],
'color' => [
'type' => TabularForm::INPUT_WIDGET,
'widgetClass' => \kartik\widgets\ColorInput::classname()
],
'author_id' => [
'type' => TabularForm::INPUT_DROPDOWN_LIST,
'items'=>ArrayHelper::map(Author::find()->orderBy('name')->asArray()->all(), 'id', 'name')
],
'buy_amount' => [
'type' => TabularForm::INPUT_TEXT,
'options'=>['class'=>'form-control text-right'],
'columnOptions'=>['hAlign'=>GridView::ALIGN_RIGHT]
],
'sell_amount' => [
'type' => TabularForm::INPUT_STATIC,
'columnOptions'=>['hAlign'=>GridView::ALIGN_RIGHT]
],
],
'gridSettings' => [
'floatHeader' => true,
'panel' => [
'heading' => '<i class="fas fa-book"></i> Manage Books',
'type' => GridView::TYPE_PRIMARY,
'after'=>
Html::a(
'<i class="fas fa-plus"></i> Add New',
$createUrl,
['class'=>'btn btn-success']
) . ' ' .
Html::a(
'<i class="fas fa-times"></i> Delete',
$deleteUrl,
['class'=>'btn btn-danger']
) . ' ' .
Html::submitButton(
'<i class="fas fa-save"></i> Save',
['class'=>'btn btn-primary']
)
]
]
]);
ActiveForm::end();