การใช้งาน Yii2 kartik DatePicker

Kartik datepicker

ติดตั้ง

php composer.phar require kartik-v/yii2-widget-datepicker "*"
or
"kartik-v/yii2-widget-datepicker": "*"

การใช้งาน ที่ view

use kartik\date\DatePicker;

<?= $form->field($model, 'start_date')->widget(DatePicker::ClassName(),
    [
    'name' => 'check_issue_date', 
    'options' => ['placeholder' => 'Select date ...'],
    'pluginOptions' => [
        'format' => 'dd/mm/yyyy',
        'todayHighlight' => true
    ]
]);?>

การทำ Visible ใน CgridView (CButtonColumn)

เป็นการกำหนดให้ ฺButton ใน CgridView ให้แดดงตามเงื่อนไข
‘Visible’ => ‘False’ // ซ่อนปุ่ม หรือ ลิงค์
‘Visible’ => ‘Expression’ // ให้แสดงตามเงื่อนไข

‘visible’=>'($data->download_enable ==0)? false:true’,

    เช่น


'download' => array(
'imageUrl' => false,
'label' => ' ',
'url' => 'Yii::app()->createUrl("dcc/Docload", array("id" => $data->id))',
'options' => array('title' => ' ', 'class' => 'btn btn-success icon-download-alt'),
'visible'=>'($data->download_enable ==0)? false:true',
),

yii uploadfile validate model

Model—->

public function rules()
{
return array(
array(‘nane, file’, ‘required’),
array(‘file’, ‘file’, ‘types’=>’doc, docx, xls,xlsx,pdf’, ‘maxSize’=> 1048576, ‘wrongType’=>’ต้องเป็น file doc xlx xlsx เท่านั้น.’),
array(‘nane, file’, ‘length’, ‘max’=>255),
array(‘id, nane, file’, ‘safe’, ‘on’=>’search’),
);
}

in Controller—–>

$model=new File;
if(isset($_POST[‘File’]))
{
$model->attributes=$_POST[‘File’];
$file=CUploadedFile::getInstance($model,’file’);
$new_name = date(“Ymd”) . ‘-‘ . time() . ‘.’ . $file->extensionName;
$model->file = $new_name;

if($model->validate()){
//$uploaded = $file->saveAs($dir.’/’.$file->getName());
$file->saveAs(Yii::app()->basePath.’/../file/’.$new_name);
//$fileName = $file->getName();
}

if($model->save())     //เก็บข้อมูลลง Database
$this->redirect(array(‘view’,’id’=>$model->id));
}

$this->render(‘up1’,array(
‘model’=>$model,
));

Replace Yii widget CGridView buttons with Bootstrap icons

$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'form-type-report-meta-data-grid',
	'dataProvider'=>$model->search(),
        'htmlOptions' => array('class' => 'table table-striped'),
	'filter'=>$model,
        'pagerCssClass' => '',
        'pager' => array(
            'class' => 'CLinkPager', 
            'selectedPageCssClass' => 'active',
            'hiddenPageCssClass' => 'disabled',
            'htmlOptions' => array('class' => 'pagination pagination-lg'),
        ),
	'columns'=>array(
                'another_boring_column',
                array(
                'header' => 'Actions',
                'class' => 'CButtonColumn',
                'buttons'=>array(
                    'update' => array(
                        'imageUrl' =>false,
                        'label' => '',
                        'options' => array( 'title'=>'Edit', 'class' => 'glyphicon glyphicon-pencil'),
                    ),
                    'view' => array(
                        'imageUrl' =>false,
                        'label' => '',
                        'options' => array( 'title'=>'View', 'class' => 'glyphicon glyphicon-eye-open'),                        
                    ),
                    'delete' => array(
                        'imageUrl' =>false,
                        'label' => '',
                        'options' => array( 'title'=>'Delete', 'class' => 'glyphicon glyphicon-remove-circle'),                        
                    ),                    
                ),
            ),
	),
));

การทำ Filter บน CGridView

Yii – ComboBox en filtros del CGridView

?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'localidad-grid',
    'itemsCssClass' => 'table table-striped',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        'id',
        'id_estado'=>array(
            'name' => 'id_estado',
                'value' => '$data->idEstado->nombre',
                'filter'=> CHtml::listData(GeoEstado::model()->findAll(array('order'=>'nombre')), 'id', 'nombre')
            ),
        'id_municipio',
        'id_parroquia',
        /*'texto',*/
        array(
            'class'=>'CButtonColumn',
        ),
    ),
)); ?>

การปรับแต่ง Toolbar Yiibooster – Ckeditorrow


<?php echo $form->ckEditorRow($model, 'description', array('options'=>array('fullpage'=>'js:true', 'width'=>'640', 'resize_maxWidth'=>'640','resize_minWidth'=>'320', 'toolbar'=>'js:[
                                                  ["Source","DocProps","-","PasteText","PasteFromWord"],
                                                  ["Undo","Redo","-","RemoveFormat"],
                                                  ["Bold","Italic","Underline","Strike","Subscript","Superscript"],
                                                  ["NumberedList","BulletedList","-","Outdent","Indent"],
                                                  ["JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock"],
                                                  ["Link","Unlink"],
                                                  ["Image","Flash","Table","HorizontalRule","SpecialChar"],
                                                  ["Format","Font","FontSize","Styles"],
                                                  ["TextColor","BGColor"],
                                                  ["Maximize","ShowBlocks"]
                                                ],')));?>