让我们一起爱米兰
站内搜搜:
移动设备
请扫描二维码
或访问
m.milan100.com
您所在的位置 -> 米兰百分百 -> TinyMce -> 在CakePHP中使用TinyMCE编辑器

在CakePHP中使用TinyMCE编辑器

点击数:1324 发表时间:2010-06-29 17:41:06 作者: 来源链接:
分享到:
分享到微信

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, ) ); 
0
很 好
0
一 般
0
差 劲
热门新闻
相关文章
上一篇:
下一篇: TinyMce介绍、环境配置与使用心得
评论区
匿名

返回首页 | 收藏本页 | 回到顶部
Copyright 2010. 米兰百分百 Powered By Bridge.
京ICP备15050557号