Home  >  Article  >  Backend Development  >  CakePHP中运用TinyMce详解

CakePHP中运用TinyMce详解

WBOY
WBOYOriginal
2016-06-13 11:03:33915browse

CakePHP中使用TinyMce详解

今天一直在纠结TinyMce在CakePHP中的使用方法,因为之前一直在使用CKEditor,没有太多的接触过TinyMce,第一次用就直接在框架中集成,所以中间造成了很多误解,搞了半天时间。这里把集成过程记载下来备用。

CakePHP官方出的有TinyMce视图助手,下载该视图助手之后,可以看到里边包含几个文件夹,先留意下/views/helpers/tiny_mce.php文件。/webroot/文件夹中包含的是TinyMce的源码。这个视图助手打包的时间比较久了,大概是在2010年,建议舍弃/webroot/中的TinyMce,直接从TinyMce下载。

首先,将TinyMce源码包中的/tinymce/jscripts/tiny_mce/这个文件夹复制到CakePHP根目录下的/app/webroot/js/中。然后将/views/helpers/tiny_mce.php文件复制到CakePHP根目录下的/app/views/helpers/文件夹中。这样主要文件就都准备完成了。开始进入编码阶段。进入到相应的视图文件中,会看到已经引入了tiny_mce文件。

在需要使用TinyMce的视图所属的控制器中,添加以下代码,

01
var $helpers = array('Session','Html','Form','TinyMce.TinyMce');

注意这里必须包含你在使用的所有试图助手,否则将被覆盖掉。添加该视图助手之后,就可以在视图文件中,像使用html,form等助手一样使用TinyMce了。下面给出一段示例代码,第一段配置TinyMce,该配置文件可以到官方网站获取更全的列表,

01
02
03
04
05
06
07
08
09
<?php
echo $this->TinyMce->editor(array(
???'mode' => "textareas",
???'theme' => "advanced",
???'mode' => "textareas",
???'plugins' => "fullpage",
???'theme_advanced_buttons3_add' => "fullpage"
));
?>

好了,配置齐全了,这里设置的是textareas类型表单会使用TinyMce编辑器,然后我们在视图代码中使用Form助手生成textarea就可以看到TinyMce编辑器了。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn