• YII2 百度富文本mini版UMEditor的使用


    官方地址:http://ueditor.baidu.com/website/umeditor.html

    教程地址:http://fex.baidu.com/ueditor/#start-start

    下载umeditor, 放到yii2文件夹, 我是放在commoncomponents

    在umeditor目录下创建一个UMEditorAsset.php文件, 编辑:

    <?php
    
    namespace commoncomponentsumeditor;
    
    
    use yiiwebAssetBundle;
    
    class UMEditorAsset extends AssetBundle
    {
        public $sourcePath = '@common/components/umeditor';
    
        public $css= [
            'themes/default/css/umeditor.css',
        ];
    
        public $js = [
            'third-party/template.min.js',
            'umeditor.config.js',
            'umeditor.min.js',
            'lang/zh-cn/zh-cn.js',
        ];
    
    }

    打开backendassetsAppAsset.php或者frontendassetsAppAsset.php(看是在后台用还是在前台用, 如果都用那么都添加)

        public $depends = [
            'yiiwebYiiAsset',
            'yiiootstrapBootstrapAsset',
            'commoncomponentsumeditorUMEditorAsset',
        ];

    这样就可以使用了, 使用也很简单:

    <?php
        $form = ActiveForm::begin(['id' => 'message-form']);
        echo $form->field($model, 'Subject')->textInput(['maxlength' => '30']);
        echo $form->field($model, 'content')->textarea([]); //用UMEditor取代这个
        echo '<div class="panel-footer panel-footer-transparent noborder-top pull-right">';
        echo Html::submitButton('<i class="fa fa-check"></i>' . Yii::t('app', '发送'), ['class' => 'btn btn-info btn-sm']);
        echo '</div>';
        ActiveForm::end();
    ?>
    
    ...
    <?php $this->beginBlock('js-block') ?>
        $(function () {
            UM.getEditor('message-content').destroy();  //因为我是用Modal弹框, 所以先销毁再创建, 否则如果关了弹窗再打开就没有了.
            var um = UM.getEditor('message-content', {});
            um.setWidth("100%");
            um.setHeight("400");
            $(".edui-body-container").css("width", "100%");
        });
    <?php $this->endBlock() ?>
    <?php $this->registerJs($this->blocks['js-block'], yiiwebView::POS_END); ?>
  • 相关阅读:
    XML to bean
    监控Informix-Url
    ld-linux.so.2: bad ELF interpreter
    Oracle
    我的北漂生活:我来北京一个月了
    C/C++ 常量的定义与应用(编程中的常量)
    C/C++ 常量的定义与应用(编程中的常量)
    英文名字的昵称(亲切的叫法)
    英文名字的昵称(亲切的叫法)
    动态规划的关键 —— 子问题 & 公式化
  • 原文地址:https://www.cnblogs.com/zrcx/p/7058461.html
Copyright © 2020-2023  润新知