yii中嵌入kindeditor
来源:互联网 发布:aucs6是什么软件 编辑:程序博客网 时间:2024/06/14 20:01
万分感谢大爱的原作者, 原文点这里
1.下载kindeditor(官网下载地址:http://kindeditor.net/down.php),并解压到Yii框架的protected/extensions目录下,比如我的路径是protected/extensions/kindeditor。
2. 在kindeditor目录创建一个php类文件KEditorWidget.php,内容如下:
<?php/** * Kindeditor编辑器输入组件 * 作者:http://www.icultivator.com * 简单使用方法: * <?php $this->widget('ext.kindeditor.KEditorWidget',array( * 'id'=>'Item_content', # Textarea id * )); ?> */class KEditorWidget extends CInputWidget{ public $id; public $language = 'zh_CN'; public $paramOptions = '{}'; /** * 初始化组件. */ public function init() { // 阻止从命令行执行. if (Yii::app() instanceof CConsoleApplication) return; /** @var CClientScript $cs */ $cs = Yii::app()->getClientScript(); $cs->registerScriptFile($this->assetsUrl.'/kindeditor-min.js', CClientScript::POS_HEAD); } /** * 运行组件. */ public function run() { $script = "KindEditor.ready(function(K){window.editor=K.create('#".$this->id."',".$this->paramOptions.");});"; /** @var CClientScript $cs */ $cs = Yii::app()->getClientScript(); $cs->registerScript($this->id, $script, CClientScript::POS_HEAD); $cs->registerScriptFile($this->assetsUrl.'/lang/'.$this->language.'.js', CClientScript::POS_HEAD); } public function getAssetsUrl() { $assetsPath = Yii::getPathOfAlias('ext.kindeditor'); $assetsUrl = Yii::app()->assetManager->publish($assetsPath, false, -1, YII_DEBUG); return $assetsUrl; }}?>
- 接下来就是使用该组件在_form.php文件中显示出kindeditor的编辑器界面了,这也比较简单:
1)简单调用:
<div class="row"> <?php echo $form->labelEx($model,'content'); ?> <?php echo $form->textArea ($model,'content',array('rows'=>6, 'cols'=>50)); ?> <?php echo $form->error($model,'content'); ?></div><?php $this->widget ('ext.kindeditor.KEditorWidget',array('id'=>'textarea_id'))?>
注意最后一句,<?php $this->widget('ext.kindeditor.KEditorWidget', array('id'=>'textarea_id'))?>
,其中的textarea_id是上面textarea文本框的id,如果不知道的话(在yii中不是然显示的),你可以打开所在的页面,然后按F12(通常是这个键),打开浏览器的调试模式,在代码那一块查看该textarea的id,如下图:
2)高级调用(设置编辑器参数),有时候我们想要更多的自定义一些选项,比如高度,宽度,以及想要显示的工具栏选项:
<div class="row"> <?php echo $form->labelEx($model,'content'); ?> <?php echo $form->textArea($model,'content', array('rows'=>6, 'cols'=>50)); ?> <?php echo $form->error($model,'content'); ?></div><?php $this->widget('ext.kindeditor.KEditorWidget', array('id'=>'Post_content','paramOptions'=>'{ width:"700px", height:"300px",}'))?>
更多编辑器设可参考这篇文章:KindEditor使用入门(二)—— 编辑器初始化参数
0 0
- yii中嵌入kindeditor
- 在YII中使用kindeditor扩展
- Yii KindEditor整合
- Yii-视图- kindeditor编辑器的应用
- YII-视图- kindeditor扩展
- kindeditor中插入图片
- asp网站后台里嵌入kindeditor在线编辑器问题
- Ext中使用KindEditor方法
- asp.net中kindeditor配置
- Eclipse中使用kindeditor插件
- JSP中使用KindEditor解决方案
- kindeditor 在函数中初始化
- Kindeditor
- KindEditor
- kindeditor
- kindeditor
- kindeditor
- kindEditor
- Java基础解惑...【Pnoter】
- mysql 学习之二 mysqldump
- Java笔记----4. 面向对象(基本概念)
- 12c In-Memory常用命令笔记
- poj3264
- yii中嵌入kindeditor
- 当人们谈论物理信息系统(CPS)的时候,他们到底在说什么?
- NSURLSession学习笔记(一)简介
- 事务隔离级别与乐观锁、悲观锁
- 2015-02-15 年前最后一编
- mobile开发中常用的css
- 两分钟开端你的Git之旅(适用于自个开发者)
- 算法精解十八(C语言版)
- 【hadoop zookeeper】安装和配置