Zend Framework Source Code Snippets

FCKEditor Helper

Bookmark and Share
1
2
3
4
56
7
8
9
1011
12
13
14
1516
17
18
19
2021
22
23
24
2526
27
28
29
3031
32
33
<?php
/**
 * @author Jeremy (Jeremy@slack5.net)
 * @link http://www.slack5.com
 */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';
    if (key_exists('height', $attr)) {
      $oFCKeditor->Height = $attr['height'];
    }
        $oFCKeditor->Value = $value;
    
    return $oFCKeditor->Create();
  }
} 
## Usage
<?php $this->rte('description', 'my default value'); ?>

Comments

bachya bachya
1 year ago

I was JUST about to write this and visited here on a hunch. Thank you!! :)

davedevelopment davedevelopment
1 year ago

Good to hear! Use case number one for this site ;)

alessiofx alessiofx
1 year ago

I have a problem, how do I install this class?


Thanks

Neantis Neantis
1 year ago

First, download on FCKEditor the corresponding files (fckeditor.php, notably).

Then, put it in your view helpers directory. If you don't have one dedicated to custom code, then, just put that file in /library/Zend/View/Helper as "Rte.php".

Don't forget to change the require_once to follow your directory layout.

alessiofx alessiofx
1 year ago

Sorry, if I want to use another directory, not to undermine the framework ??

Court Ewing Court Ewing
1 year ago

In that case, you'd probably want to change the name of the class so that it isn't using the "Zend" prefix, and then add your new prefix and its path to your view:

$view = Zend_View();
$view->addHelperPath('Path/To/Helpers', 'My_View_Helper_');

Then, assuming your view script is in the scope of that view object, you could use the view helper just like any of Zend's prepackaged helpers.

haris haris
1 year ago

Greetings,

where can I download the needed files??

Thank you.

PS. Really great work. I feel thankfull.

Slack5 Slack5
1 year ago

You can download fckeditor from http://www.fckeditor.net/

copy & paste the code into your rte helper file.

You must login before commenting on a snippet. If you do not have an account, please register.

Snippet description

Helper to display fckeditor.

Snippet details

Created:
Slack5 Slack5
1 year ago
Edited:
Slack5 Slack5
1 year ago
Revision Id:
31
Edit Message:
Initial Release
Tags:
fckeditor
Comments:
8
Views:
207
Points:
1 (1 votes)

History

r31

Initial Release

Slack5 Slack5
1 year ago