yii 整合 ueditor

本文介绍了如何在Yii 1.1.15版本中详细整合UEditor 1.4.3,包括下载、文件放置及ueditor.config.js的配置修改,为在Yii框架中使用UEditor提供清晰步骤。
摘要由CSDN通过智能技术生成

在网上找了很多相关的, 但都不太详细, 参考了下,自己终于写出来了.

首先说说我的版本

yii  : 1.1.15

ueditor : 1.4.3 utf8

事不宜迟, 马上开始.

首先在官网下载ueditor, 解压后把文件夹移动到yii项目的根目录喇

然后打开ueditor.config.js 修改

var URL = window.UEDITOR_HOME_URL || '/ueditor/';//getUEBasePath();原来的

增加 ActiveForm.php, 用来给yii 生成widget

ActiveForm.php 代码

class ActiveForm extends CActiveForm {

    public function ueditor($model, $attribute, $htmlOptions=array()) {
        //得到这个插件的name
        CHtml::resolveNameID($model, $attribute, $htmlOptions);
        $attr = 'name="'.$htmlOptions['name'].'" style="'.$htmlOptions['style'].'"';
        $content = $model->content?$model->content:'';
        $str = '<script type="text/javascript" src="/ueditor/ueditor.config.js"></script>';
        $str .='<script type="text/javascript" src="/ueditor/ueditor.all.min.js"></script>';      
        $str .= '<script id="editor" type="text/plain" '.$attr.'>'.html_entity_decode($content).'</script>';    
        $str .= '<script type="text/javascript">var ue = UE.getEditor(\'editor\');</script>';
        return $str;
    }
}

最后在我们需要使用ueditor的地方去加载这个widget

  $form = $this->beginWidget('ActiveForm', array(
                'id' => 'user-form',
                // Please note: When you enable ajax validation, make sure the corresponding
                // controller action is handling ajax validation correctly.
                // There is a call to performAjaxValidation() commented in generated controller code.
                // See class documentation of CActiveForm for details on this.
                'enableAjaxValidation' => false,
            ));
            ?>
            <fieldset>
                <p>
<?php echo $form->labelEx($model, 'title'); ?>
<?php echo $form->textField($model, 'title', array('size' => 30, 'maxlength' => 30,'class' => 'text-input small-input')); ?>
<?php echo $form->error($model,'title'); ?>
                </p>

                <p>
<?php echo $form->labelEx($model, 'description'); ?>
<?php echo $form->textField($model, 'description', array('size' => 30, 'maxlength' => 30,'class' => 'text-input small-input')); ?>
                </p>

                <p>
<?php echo $form->labelEx($tmodel, 'content'); ?>
<?php echo $form->ueditor($tmodel,'content',array('style'=>'width:850px;height:400px;'));//style是限定文本框的大小?>
                </p>
                <p>
<?php echo CHtml::submitButton($model->isNewRecord ? '新建' : '保存',array('class'=>'button')); ?>
                </p>
            </fieldset>
            <div class="clear"></div>
<?php $this->endWidget(); ?>

我刚学YII, 这里只是个demo 做得比较简单, 可能实现的方法比较笨拙, 就在这里抛砖下吧, 大家有更好的方法也可以告诉我. 谢谢~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值