zoukankan      html  css  js  c++  java
  • 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); ?>
  • 相关阅读:
    实验4-1-5 韩信点兵 (10分)
    实验4-1-6 求分数序列前N项和 (15分)
    实验7-1-5 选择法排序 (20分)
    实验7-1-2 求最大值及其下标 (20分)
    第一次个人编程作业
    3.Vue.js-目录结构
    2.VUEJS-安装
    1.Vuejs-第一个实例
    Mybatis通用Mapper介绍与使用
    商城项目团购之定时任务2
  • 原文地址:https://www.cnblogs.com/zrcx/p/7058461.html
Copyright © 2011-2022 走看看