Skip Navigation LinksHome > Categories > Code from a Category

Integrating FCKeditor in Zend_Form



User Name: serfcompany
Name: Serf
Contact Me: www.datawebcoder.com
Home Page: www.datawebcoder.com
php,mysql,javascript,html,css. Preferable working with Zend Framework. Good know javascript. I worked with various, javascript frameworks such as(jquery, YUI3, extjs, sencha touch). [More]
Viewed Times: 1890
Add Date: 07/11/2012
How can I use FCKeditor or any other WYSIWYG-editor, along with Zend_Form?

Even a relatively simple matter. There are many ways by which you can do it, but let's look at two of the most suitable, in my opinion:


* Add some JavaScript to your Kind (view).
* Create Zend_Form_Decorator


We will use the FCKeditor, but you can use the technique shown to others, and to TinyMCE as well.


Setting


We look at each method to configure FCKeditor with Zend_Form. We will assume that you have a controller with a View (view), to which you add a simple form class like this:



Note that we specify the ID of the form - you need to assign item ID for this to work, do not forget about it!


Method 1: Adding JavaScript to the form (view)


It seems the simplest solution of the two, but not very reusable, and always require manual implementing this step.
Simply put, we derive the form in (view) and then include some code to JavaScript, which will replace the textarea inserts FCKeditor.



When the page is loaded, run the above JavaScript code and replaces the textarea on the WYSIWYG-editor. Note that the code for JavaScript, you must enable FCKeditor scripts to section head. Also, if you want to place a script block to the section head, remember that it should hang on window.onload, otherwise just would not work.


Method 2: Create a decorator


This solution requires a class decorator. It's a bit harder than the first method, but after we create a decorator, it will be easier for repeated use.
A decorator will not change the layout elements, instead, we add some JavaScript code to the Assistant inlineScript.
The benefits of this solution is that the editor will work, and even if something goes wrong - you'll see a simple textarea. If we were using, say, a library of integration FCKeditor PHP, would not display anything at all.



As you can see, decorator relatively simple. It just adds JS-code and returns the desired inlineScript not modify the content. We also have a method to set the base path, FCKeditor, if it is different.
Use this decorator is very simple:



Now, when we did render form as (view) and in the end render inlineScript layout before the closing body, we got a great block of FCKeditor.


Troubleshooting


If you have any problems with the launch of FCKeditor, make sure it is available. Sometimes, your rules rewrite, file. Htaccess, can do a ban, you need to open access for script files. The easiest way to make sure, in this case is to try to open the script directly from the browser.


Conclusions.


Integrating FCKeditor in Zend_Form is a very simple task. We can even make it easy to reuse by creating a custom decorator.

Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Details**:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
 
    
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.