yii2使用twig模板组件

twig 2017-12-05 浏览(3827 评论(0

NO/OFF

{{ form.field(model, 'notice').widget('kartik\\widgets\\SwitchInput')|raw }}

单个时间

{{ form.field(model, 'created').widget('kartik\\widgets\\DateTimePicker', {'pluginOptions':{'autoclose':'true','format':'yyyy-mm-dd hh:ii:ss'}})|raw }}

时间范围

{{ form.field(model,'created',{'inputOptions':{'class':'form-control' }}).label('选择时间',{'class':'control-label col-lg-2'}).widget('\\kartik\\daterange\\DateRangePicker',{'convertFormat':true,'pluginOptions':{'format':'Y-m-d','separator':' - ','opens':'left'}})|raw }}


富文本编辑器

{{ form.field(model,'desc').widget('\\mihaildev\\ckeditor\\CKEditor',{'name':'des','editorOptions':{'preset':'base','inline':false,'filebrowserImageUploadUrl':'/upload'}})|raw.label(null,{'class':'control-label col-lg-3'})|raw }}

markdown文本编辑器

1.{{ form.field(model,'desc').widget('\\ijackua\\lepture\\Markdowneditor')|raw.label(null,{'class':'control-label col-lg-3'})|raw }}

2.{{ form.field(model,'desc').widget('\\yidashi\\markdown\\Markdown')|raw.label(null,{'class':'control-label col-lg-3'})|raw }}

3.{{ form.field(model,'desc').widget('\\kartik\\markdown\\MarkdownEditor')|raw.label(null,{'class':'control-label col-lg-3'})|raw }}
(第三种需要在mail.php中配置)
'modules' => [
    'markdown' => [
            'class' => 'kartik\markdown\Module',
    ],
],

复选框(删除)

0:{
    'class':'\\kartik\\grid\\CheckboxColumn',
},

多选删除用例
{% block content %}
<form id="create-form-package" method="post" action="/keywords/delete-more-reply">
    {{
    widget('\\kartik\\grid\\GridView', {
        'dataProvider':dataProvider,
        'hover':true,
        'resizableColumns':true,
        'columns':{
            0:{
                'class':'\\kartik\\grid\\CheckboxColumn',
            },
            1:'id',
            2:'words',
            3:'reply',
            4:{
                'attribute':'type','value':model.showType(),'format':'raw',
            },
            5:'created',
            6:{
                'class':'\\common\\extensions\\Grid\\GridActionColumn',
                'template':'{update-reply}{delete-reply}',
                'header':'操作',
            },
    }})
}}
<button class="btn btn-sm btn-danger" type="button" onclick="submitDelete();">删除</button>
</form>
<script type="text/javascript">
    function submitDelete(){
        var length = 0;
        $("input[name='selection[]']:checked").each(function(){
               length +=1;
        });
        if(length > 0){
            $("#create-form-package").submit();
        }else{
            $('#package_error').click();
        }
    }
</script>

select2下拉框带搜索功能(\kartik\select2\Select2)

1.{{ form.field(model,'tags').widget('\\kartik\\select2\\Select2',{'data':Tags,'options':{'multiple': true,'placeholder' : '请选择标签'}})|raw }}

2.{{ form.field(model,'tags').widget('\\kartik\\select2\\Select2',{'data':Tags,'options':{'placeholder':'请选择标签'},'pluginOptions':{'allowClear':true}})|raw }}

打赏

如果此文对你有所帮助,请随意打赏鼓励作者^_^

黄信强博客