FCEeditor with Zend Framework —
My current project I’m building with the Zend Framework and I needed to be able to use the fckeditor.
Integration is extremely easy using a helper with the framework.Here is the helper that I am currently using.
<?php
require_once(str_replace('admin_application', 'admin', APPLICATION_DIRECTORY).'/js/fckeditor/fckeditor.php');
class Zend_View_Helper_Rte
{
function rte($name, $value = null, $attr = array())
{
$baseUrl = str_replace('/index.php', '', Zend_Controller_Front::getInstance()->getBaseUrl());
$headLink = new Zend_View_Helper_HeadLink();
// include js & css for rte
$headScript = new Zend_View_Helper_HeadScript();
$headScript->headScript()->appendFile($baseUrl.'/js/fckeditor/fckeditor.js');
$oFCKeditor = new FCKeditor($name) ;
$oFCKeditor->BasePath = $baseUrl.'/js/fckeditor/';
$oFCKeditor->Config['SkinPath'] = $oFCKeditor->BasePath."editor/skins/office2003/";
$oFCKeditor->Height = '400'; // default height
if (key_exists('height', $attr)) {
$oFCKeditor->Height = $attr['height'];
}
$oFCKeditor->Value = $value;
return $oFCKeditor->Create();
}
}
As this is being used in the application directory, I needed to replace the value in APPLICATION_DIRECTORY with my public direcotry so that my webpages know that path to the fckeditor files.
The file is saved as Rte.php in my helpers folder.
Now to use the editor, all I have todo is call the helper function providing the input name to use, and default value like:
<?php $this->rte('description', 'my default value'); ?>
Categorised as: Javascript | Zend Framework