Using FCKEditor with Zend Framework (File Browser Enabled)

If you are trying to use FCKEditor with Zend Framework, you might be getting errors where ZF is trying to look for a controller named: “FCKEditor”.

To fix this, open your .htaccess file in your /html directory and add “xml” and “php”. Like something below:

RewriteEngine on
RewriteRule !\.(htm|html|txt|swf|js|ico|gif|jpg|png|css|php|xml)$ index.php

This is so that all files with xml and php extension does not thrown to index.php - which is the bootstrap file of the Zend Framework. You might be asking why add “php” in the .htaccess. Well, FCKEditor has a built-in File Browser. The File Browser has connectors for different server side programming languages - and the default is PHP. So in short, there are PHP files inside the FCKEditor directories. It gets executed when you enable the File Browser in FCKEditor. And FCK also loads XML files. Adding both xml and php in the rewrite rule would allow FCKEditor to run properly inside a Zend Framework application.

The View File
Now, in your view file, you can have something like this:

< script type="text/javascript" >
    window.onload = function()
    {
        if(document.getElementById('content_text')) {
            var oFCKeditor = new FCKeditor('content_text') ;
            oFCKeditor.BasePath = "< ?=$this->baseUrl ?>/js/fckeditor/" ;
            oFCKeditor.Height = 500;
            oFCKeditor.ReplaceTextarea() ;
        }
    }
< / script >

Notice the $this->baseUrl in the oFCKeditor.BasePath? Take note of it.

The File Browser Config
Now in /home/ekini/public_html/js/fckeditor/editor/filemanager/connectors/php/config.php I have UserFilesPath set to /images/uploads/ - see below:

$Config['UserFilesPath'] = '/images/uploads/' ;

Make sure the you have CHMOD to 777 the uploads directory.

Bilgehan, got his FckEditor working in Windows using the following config for FckEditor:

$Config[’UserFilesPath’] = ‘/user/’ ;
$Config[’UserFilesAbsolutePath’] = ‘C:/Documents and Settings/Bill/Desktop/v.2.subversion/httpdocs/user/’;

Thanks Bilgehan ;)

I hope that I didn’t miss anything. It took me more than an hour to figure things out :-(
If you have comments, suggestions or corrections feel free to post them below.


Subscribe to comments Comment | Trackback |
Post Tags: ,

Browse Timeline


Comments ( 42 )

Cool, I have a question for you, did you set this variable too: $Config[’UserFilesPath’] ? cuase if I don’t set it I can upload files and I can’t see the files browser, I got an error, something about that can’t create some folders.

jfalvarez added these pithy words on Jan 08 08 at 6:10 am

the $Config[’UserFilesPath’] is set to /images/uploads

The full path to this - i think is - /home/ekini/public_html/images/uploads

It is found in the html folder of your ZF app.
/html
index.php (bootstrap file)
/js
/images
/uploads (CHMOD to 0777)

make sure you have the xml, js, php and other file extensions included the .htaccess list above though.

hope this helps. if there are still errors, just send a reply to this post and il double check my settings in my site.

-wenbert

Wenbert added these pithy words on Jan 08 08 at 7:31 am

Well, this is my .htaccess fike data:

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css|pdf|eps|ai|doc|xls|ppt|zip|rar|sit|jpeg|swf|xml|xst|txt|js\.php|jar|php)$ index.php

Doesn’t work, still the framework thinks that folder is a controller/action. I’m using fckeditor 2.5.1, latest one. And this is the config in my php connector:

$Config[’Enabled’] = true ;
$Config[’UserFilesPath’] = ‘/userfiles/’ ;
// $Config[’UserFilesAbsolutePath’] = ‘/userfiles/’ ;

The problem is this, If I don’t set $Config[’UserFilesAbsolutePath’] with all the absolute path, doesn’t work, I mean, I got an error about that can’t create some folders, :S, you are using that variable ?

jfalvarez added these pithy words on Jan 08 08 at 12:54 pm

you have a typo in your .htaccess file.
check the |js\.php| part…
it should be |js|php|
no \.

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css|pdf|eps|ai|doc|xls|ppt|zip|rar|sit|jpeg|swf|xml|xst|txt|js|php|jar|php)$ index.php

if that doesn’t work, i will check the files on the application when i get home. im still at work :P

Wenbert added these pithy words on Jan 08 08 at 2:39 pm

hehehe, js.php is a special file :P, js + php to print some stupid constants and stuff with php.

jfalvarez added these pithy words on Jan 08 08 at 10:49 pm

Great stuff man.I have a slight problem though :)
My installation was a little bit different then yours. I like all my 3rd party libs under library folder. So I created the directory FCKeditor under library folder and put fckeditor.php fckeditor_php4.php and fckeditor_php5.php under this.rest of the files went to /httpdocs/scripts/FCKeditor

And in the controller/action
$oFCKeditor = new FCKeditor(’FCKeditor1′);
$oFCKeditor->BasePath = ‘/scripts/FCKeditor/’;
$oFCKeditor->Value = ‘Default text in editor’;
$returnHTML= $oFCKeditor->CreateHtml();
$this->view->editor = $returnHTML;

and of course in the phtml file
editor?>

suprisingly the editor comes and perfectly. all buttons work etc. but when I try to browse server for image upload I get
Error creating folder “redirt:index.php/” (can’t create directory: directory) message.

in the configuration file I have
$Config[’Enabled’] = true ;
$Config[’UserFilesPath’] = ‘/userimages’ ;
and of course the directory exists.

as I honestly believe that your are a genius, could you please help me on this one?
Thanks
B.

Bilgehan added these pithy words on Jan 12 08 at 7:03 am

sorry, made a mistake
===========
and of course in the phtml file
editor ? >

Bilgehan added these pithy words on Jan 12 08 at 7:05 am

Hello, hope ur doing fine. Is the directory writable? Have u chmod it to 777?

Wenbert added these pithy words on Jan 12 08 at 1:55 pm

@jfalvarez well if ZF stil thinks that fckeditor is a controller then the .htaccess part is still sending stuff to index.php (boobstrap). Try double checking that part — htaccess

Wenbert added these pithy words on Jan 12 08 at 2:00 pm

Hi wenbert,
This is a windows xp machine I am trying on, so I don’t think the permissing will be an issue.

Bilgehan added these pithy words on Jan 13 08 at 3:47 am

hi Bilgehan,
can you check your apache error logs?
did u try removing the js.php? and just use .php instead? (in the .htaccess file)

i just had the same problem - ZF was looking for an fckEditor controller - the problem was that i forgot to edit the .htaccess file beside the index.php (bootstrap)

Wenbert added these pithy words on Jan 13 08 at 3:33 pm

Wenbert, thanks for your time and help!
My htaccess file says
RewriteRule !\.(htm|html|txt|swf|js|ico|gif|jpg|png|css|php|xml)$ index.php
and apache error logs is clean.
you can check the page here
http://fmuw.dyndns.org/test/index/fck

Bilgehan added these pithy words on Jan 13 08 at 11:55 pm

Good news!
I have changed the config.php as follows
$Config[’UserFilesPath’] = ‘/user/’ ;
$Config[’UserFilesAbsolutePath’] = ‘C:/Documents and Settings/Bill/Desktop/v.2.subversion/httpdocs/user/’;
and everything works fine!
I hope this helps others.

Thanks again Wenbert.

Bilgehan added these pithy words on Jan 14 08 at 3:05 am

Hi Bilgehan,

Thanks for your input! :-)
I will put some notes regarding file paths for Windows machines…

Wenbert added these pithy words on Jan 14 08 at 10:38 am

It’s easier than that: just put a .htaccess file in your fckeditor folder with just RewriteEngine Off in it. That’s it :)

Hendi added these pithy words on Mar 12 08 at 8:59 pm

Thanks hendi! :-) I never thought of that… way better and easier solution…

Wenbert added these pithy words on Mar 12 08 at 9:21 pm

You’re the machine!!. I´m spanish!!
You’re the best!!
Thank you!!!

Pablo Triviño added these pithy words on Apr 15 08 at 11:18 pm

more elegant version of .htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php

at added these pithy words on Aug 05 08 at 2:52 am

I just spend 3h looking for an answer about the FCK and ZF - it’s Windows case - the best solution is to set things like that:

$Config[’UserFilesPath’] = ‘/images/upload/’;

AND COMPLETLY COMMENT
$Config[’UserFilesAbsolutePath’]!!!!!!

Then it’s universal (working both on Win and Linux). Of course previously change .htaccess.

Chlebik added these pithy words on Aug 07 08 at 7:19 pm

Ha!It worked for me too.The only thing that I didn’t found here is where exactly should I put my .htaccess with RewriteEngine Off..
So you should put it in JS folder. E.g. web_root/js/.htaccess

Tnx,u helped me a lot ;)

pouderstream added these pithy words on Aug 15 08 at 11:32 pm

Hi,
It seems hendi’s system is the best. But where to place FCKeditor folder? In application? or in the public folder of the site?
Thanks

Nearher added these pithy words on Sep 10 08 at 2:05 pm

Nearher,

You place it inside: public/js/FCKEditor
On your views/layouts, you can use the base_url to call the FCKEditor files.

Regards,
Wenbert

Wenbert added these pithy words on Sep 10 08 at 3:40 pm

Hi,

I am new in zend…
I wann a integrate FckEditor in my application but first i am not getting this fckeditor folder to upload this in our Library folder ya somewhere ..?

and how to use that in model as well as in phtml file

Please give me that folder with step by step that i can implement this

i am using xampp

Trushal added these pithy words on Nov 22 08 at 1:18 pm

What about this little script:

window.onload = function() {
var textareas = document.getElementsByTagName(”textarea”);
if (textareas) {
for (i=0; i<textareas.length; i++) {
var oFCKeditor = new FCKeditor(textareas[i].name);
oFCKeditor.BasePath
oFCKeditor.BasePath = “baseUrl ?>/addons/fckeditor/” ;
oFCKeditor.Width = 640;
oFCKeditor.Height = 320;
oFCKeditor.ToolbarSet = ‘Basic’;
oFCKeditor.ReplaceTextarea() ;
}
}
}

It finds all textareas in the document and transforms them, so you don’t have do to it each time.

Christian Schramm added these pithy words on Jan 25 09 at 1:02 am

Sorry, there was 1 line too much.

window.onload = function() {
var textareas = document.getElementsByTagName(”textarea”);
if (textareas) {
for (i=0; i<textareas.length; i++) {
var oFCKeditor = new FCKeditor(textareas[i].name);
oFCKeditor.BasePath = “baseUrl ?>/addons/fckeditor/” ;
oFCKeditor.Width = 640;
oFCKeditor.Height = 320;
oFCKeditor.ToolbarSet = ‘Basic’;
oFCKeditor.ReplaceTextarea() ;
}
}
}

Christian Schramm added these pithy words on Jan 25 09 at 1:03 am

Thanks a lot!!!

leon added these pithy words on Mar 09 09 at 3:13 am

Hi,
Has anyone had any luck getting styles in the fck_editorarea.css file to show up in the editor area? Everything else in the editor seems to be working fine except for this feature.

I have checked my apache and php logs, no errors. set the path to FCKConfig.EditorArea = ‘/css/fck_editorarea.css’ ;

and thats where the file is (ie public/css/fck_editorarea.css)

Quite stuck now! any help gratefully recieved.

Will

Will added these pithy words on Apr 04 09 at 10:21 am

Guys, just remember, adding to RewriteRule php extension is a big security breach.

jast call me Aw. added these pithy words on Jun 04 09 at 2:11 pm

Hello,
i got a problem i made the js in my View and now he say

Fatal error: Uncaught exception ‘Zend_Controller_Dispatcher_Exception’ with message ‘Invalid controller specified (fckeditor)’ in /var/www/test/library/Zend/Controller/Dispatcher/Standard.php:249 Stack trace: #0 /var/www/test/library/Zend/Controller/Front.php(914): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 /var/www/test/referenz2/public/index.php(41): Zend_Controller_Front->dispatch() #2 {main} thrown in /var/www/test/library/Zend/Controller/Dispatcher/Standard.php on line 249

What is wrong?

Illus23 added these pithy words on Jun 12 09 at 4:15 pm

yes, i got it … haven’t uploaded the .htaccess

Illus23 added these pithy words on Jun 12 09 at 7:14 pm

heloo

tommybui added these pithy words on Jun 24 09 at 10:36 am

// this file is in index.phtml

Height = “300px”;
$oFCKeditor->Width = “730px”;
$oFCKeditor->BasePath = $sBasePath ;
$oFCKeditor->Value = ‘aaaaaa’ ;
$oFCKeditor->Create() ;
?>
//.htaccess
RewriteEngine on
RewriteRule !\.(htm|html|txt|swf|js|ico|gif|jpg|png|css|php|xml)$ index.php
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1

=> didn’t appear anything , can bro help me ?

tommybui added these pithy words on Jun 24 09 at 10:38 am

// this file is index.phtml

Height = “300px”;
$oFCKeditor->Width = “730px”;
$oFCKeditor->BasePath = $sBasePath ;
$oFCKeditor->Value = ‘aaaaaa’ ;
$oFCKeditor->Create() ;
?>

tommybui added these pithy words on Jun 24 09 at 10:39 am

//

//Height = “300px”;
$oFCKeditor->Width = “730px”;
$oFCKeditor->BasePath = $sBasePath ;
$oFCKeditor->Value = ‘aaaaaa’ ;
$oFCKeditor->Create() ;
?>

tommybui added these pithy words on Jun 24 09 at 10:41 am

hp require_once ‘C:/Program Files/Zend/Apache2/htdocs/SimpleHo/application/default/views/scripts/test/fckeditor/fckeditor.php’ ;?>

<?php
$ctrl_name = ‘comments’;
$sBasePath = ‘fckeditor/’;
$oFCKeditor = new FCKeditor($ctrl_name) ;

tommybui added these pithy words on Jun 24 09 at 10:41 am

@tommybui, I am not familiar with Windows. But can you try to use \\ double-backslashes instead?

Wenbert added these pithy words on Jun 24 09 at 11:55 am

i mean , fckeditor didn’t appear on the screen

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1

Height = “300px”;
$oFCKeditor->Width = “730px”;
$oFCKeditor->BasePath = $sBasePath ;
$oFCKeditor->Value = ‘aaaaaa’ ;
$oFCKeditor->Create() ;
?>

tommybui added these pithy words on Jun 24 09 at 12:39 pm

i mean , fckeditor didn’t appear on the screen

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1

$ctrl_name = ‘comments’;
$sBasePath = ‘C:/Program Files/Zend/Apache2/htdocs/SimpleHo/application/default/views/scripts/index/fckeditor/’;
$oFCKeditor = new FCKeditor($ctrl_name) ;
$oFCKeditor->Height = “300px”;
$oFCKeditor->Width = “730px”;
$oFCKeditor->BasePath = $sBasePath ;
$oFCKeditor->Value = ‘aaaaaa’ ;
$oFCKeditor->Create() ;

tommybui added these pithy words on Jun 24 09 at 12:40 pm

Try to add php in RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
If it still did not work, try to ask ZF mailing list: http://www.nabble.com/Zend-Framework-Community-f16154.html

Wenbert added these pithy words on Jun 24 09 at 12:47 pm

i added but still not work , do you have nick yahoo , i want to chat with you .

tommybui added these pithy words on Jun 24 09 at 12:52 pm

hey , is there htaccess in fckeditor ?? ,
that htaccess above i add is under public’s folder

tommybui added these pithy words on Jun 24 09 at 1:16 pm

Programmed fck editor right into zend forms
Instructions Demo

craig added these pithy words on Jun 26 09 at 5:54 am

Add a Comment


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> <pre lang="" line="">


© Copyright 2007 eKini: Web Developer Blog . Thanks for visiting!