Оживим сообщество Zend Framework. :)
Сегодня об интегрировании визуального редактора FCKeditor в ZF.
Существует множество способов это сделать. Расскажу о самом, на мой взгляд, простом.
Реализуем это сделав FCKeditor элементом Zend_Form.
Для этого создадим класс formwysiwyg.
Вариант 1. Некошерный.
Файл класса создаем в папке library/Zend/Form/Element. Можно для этого скопировать имеющийся там файл Textarea.php, переименовав его в FormWysiwyg.php и отредактировать следующим образом:
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Form_Element_Xhtml */
require_once 'Zend/Form/Element/Xhtml.php';
/**
* Textarea form element
*
* @category Zend
* @package Zend_Form
* @subpackage Element
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Textarea.php 16218 2009-06-21 19:44:04Z thomas $
*/
class Zend_Form_Element_FormWysiwyg extends Zend_Form_Element_Xhtml
{
/**
* Use formTextarea view helper by default
* @var string
*/
public $helper = 'formWysiwyg';
}
Вариант 2. Кошерный.
Создаем файл класса в папке для собственных плагинов. У меня этот папка App в папке library. Подключается она строчкой
autoloaderNamespaces[] = "App_"
в файле application.ini.
В этой папке создаем папку FormElement и в ней файл FormWysiwyg.php
require_once 'Zend/Form/Element/Xhtml.php';
class App_FormElement_FormWysiwyg extends Zend_Form_Element_Xhtml
{
public $helper = 'formWysiwyg';
}
Далее надо создать хэлпер FormWysiwyg.php в папке хэлперов. У меня это в папке application/views/helpers/.
/** * Abstract class for extension
*/
require_once 'Zend/View/Helper/FormElement.php';
require_once 'js/fckeditor/fckeditor.php'; // папка где лежит редактор
/**
* Helper to generate a "textarea" element
*
* @category Zend
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_View_Helper_FormWysiwyg extends Zend_View_Helper_FormElement
{
/**
* @access public
*
* @param string|array $name If a string, the element name. If an
* array, all other parameters are ignored, and the array elements
* are extracted in place of added parameters.
*
* @param mixed $value The element value.
*
* @param array $attribs Attributes for the element tag.
*
* @return string The element XHTML.
*/
public function formWysiwyg($name = null, $value = null, $attribs = null)
{
if(is_null($name) && is_null($value) && is_null($attribs)) {
return $this;
}
$info = $this->_getInfo($name, $value, $attribs);
extract($info); // name, value, attribs, options, listsep, disable
$editor = new FCKeditor($name);
// настройка параметров редактора
$editor->BasePath = '/js/fckeditor/' ;
$editor->ToolbarSet = empty($attribs['ToolbarSet']) ? 'Default' : $attribs['ToolbarSet'];
$editor->Width = empty($attribs['Width']) ? '70%' : $attribs['Width'];
$editor->Height = empty($attribs['Height']) ? 200 : $attribs['Height'];
$editor->Value = $value;
$editor->Config['BaseHref'] = $editor->BasePath;
$editor->Config['CustomConfigurationsPath'] = $editor->BasePath.'editor/fckconfig.js';
$editor->Config['SkinPath'] = $editor->BasePath.'editor/skins/office2003/';
return $editor->createHtml();
}
}
Всё. Теперь вы можете добавлять его как элемент Zend_Form. Например:
$content = new App_FormElement_FormWysiwyg('content'); //new Zend_Form_Element_FormWysiwyg('content'); для некошерного случая
$content->setLabel('Текст');
$content->setRequired(true);
$content->addFilter('StringTrim');
$this->addElement($content);
Данный пост не претендует на мегакрутость, просто один из способов. :)