TinyMCE Editor 小巧实用,是网页文章编辑器之首先,最近在用CakePHP做一个小项目正好用到,记录一下。
首先下载TinyMCE ,并把压缩包内tinymce/jscripts/tiny_mce 目录整个拷贝到webroot/js 目录下,然后在需要用到TinyMCE的Controller里加入,代码如下:
var $helpers = Array ( 'Form' , 'Tinymce' ) ;
然后建立views/helpers/tinymce.php 文件,内容如下:
< ?php class TinyMceHelper extends AppHelper { // Take advantage of other helpers var $helpers = array ( 'Javascript' , 'Form' ) ; // Check if the tiny_mce.js file has been added or not var $_script = false ; /** * Adds the tiny_mce.js file and constructs the options * * @param string $fieldName Name of a field, like this "Modelname.fieldname", "Modelname/fieldname" is deprecated * @param array $tinyoptions Array of TinyMCE attributes for this textarea * @return string JavaScript code to initialise the TinyMCE area */ function _build( $fieldName , $tinyoptions = array ( ) ) { if ( ! $this -> _script) { // We don't want to add this every time, it's only needed once $this -> _script = true ; $this -> Javascript -> link ( '/js/tiny_mce/tiny_mce.js' , false ) ; } // Ties the options to the field $tinyoptions [ 'mode' ] = 'exact' ; $tinyoptions [ 'elements' ] = $this -> __name( $fieldName ) ; return $this -> Javascript -> codeBlock ( 'tinyMCE.init(' . $this -> Javascript -> object ( $tinyoptions ) . ');' ) ; } /** * Creates a TinyMCE textarea. * * @param string $fieldName Name of a field, like this "Modelname.fieldname", "Modelname/fieldname" is deprecated * @param array $options Array of HTML attributes. * @param array $tinyoptions Array of TinyMCE attributes for this textarea * @return string An HTML textarea element with TinyMCE */ function textarea( $fieldName , $options = array ( ) , $tinyoptions = array ( ) ) { return $this -> Form -> textarea ( $fieldName , $options ) . $this -> _build( $fieldName , $tinyoptions ) ; } /** * Creates a TinyMCE textarea. * * @param string $fieldName Name of a field, like this "Modelname.fieldname", "Modelname/fieldname" is deprecated * @param array $options Array of HTML attributes. * @param array $tinyoptions Array of TinyMCE attributes for this textarea * @return string An HTML textarea element with TinyMCE */ function input( $fieldName , $options = array ( ) , $tinyoptions = array ( ) ) { $options [ 'type' ] = 'textarea' ; return $this -> Form -> input ( $fieldName , $options ) . $this -> _build( $fieldName , $tinyoptions ) ; } } ?>
然后在要使用TinyMCE的View页面直接用$tinymce->input(‘fieldname’);来调用就可以了。例如:
< ?php // init TinyMCE Editor echo $tinymce -> input ( 'content' , array ( 'label' => false , 'style' => 'height:350px; width:98%;' , 'error' => '请输入内容' ) , array ( 'mode' => 'textareas' , 'theme' => 'advanced' , 'theme_advanced_toolbar_location' => 'top' , 'theme_advanced_toolbar_align' => 'left' , 'theme_advanced_statusbar_location' => 'bottom' , //'theme_advanced_resizing' => true, ) ) ;
参考:http://bakery.cakephp.org/articles/view/tinymce-helper-1
近期本人开通了微信订阅号“CakePHP学习”,欢迎大家的关注。
相关推荐
cakephp适用的Tinymce所见即所得编辑器组建
CakePHP的blog例子(增加了后台功能,嵌入了TinyMCE编辑器) 我的新博客http://www.cakesns.cn
一些cakephp3.0 的使用总结
cakephp 中文手册cakephp 中文手册cakephp 中文手册cakephp 中文手册
cakephp中acl详解
全面的cakephp中文文档
cakephp框架,api中文手册,初学者必看
cakephp中acl详解
cakephp中文手册 请注意,此文件不是API!
使用CakePHP框架如何创建验证器的文档。验证器可以通过在控制器中加入以下代码被创建,一旦创建了验证器,我们就可以使用验证器实例验证数据。
CakePHP中文手册
CakePHP有多个特点,这些特点让CakePHP成为了快速开发框架中的佼佼者之一。 1.活跃友好的社区 2.灵活的许可协议(Licensing) 3.兼容PHP4和PHP5 4.数据库交互和简单查询的集成 5.应用程序Scaffolding 6....
打包下载,里面有CakePHP的框架源码,下载后可直接使用,版本是1.1的,稳定版;CakePHP的分页组件源码;CakePHP的中文及英文教程,CHM格式;CakePHP的中文打印版教程,WORD格式,下载后可直接打印,方便的;CakePHP...
CakePHP是一个开源的PHP on rails的full-stack framework。最开始从Ruby On Rails框架里得到灵感。程序员可使用它来快速创建的Web应用程序。我们的首要目的是使你以一种预置的快速且不失灵活性的方式开展工作。
cakephp中文手册.pdf
cakephp-jwt-auth, 使用JSON网络令牌进行身份验证的CakePHP插件 CakePHP认证插件 包含AuthComponent类认证的插件,用于使用 JSON网络令牌进行身份验证。 你可以在这里详细阅读关于JSON网络令牌规范的详细说明。要求...
打包下载,里面有CakePHP的框架源码,下载后可直接使用,版本是1.1的,稳定版;CakePHP的分页组件源码;CakePHP的中文及英文教程,CHM格式;CakePHP的中文打印版教程,WORD格式,下载后可直接打印,方便的;CakePHP...
这是CakePHP 1.2 API 中文文档,是中文API。解压后,找到其中index.htm文件,打开浏览就可以了。相信对不喜欢E文人有很大帮助,其它的就不多说了,自己看就知道了。
2:cakephp中虽然对模型的操作方法中并没有提供像上面提到的连贯方法 但是cake框架提供了一个containable行为类来更好的完善模型关联中遇到的上述问题 ">1:thinkphp中通过框架提供的连贯操作Model >join ‘other ...