Aug 24 2010

Adding CKEditor & CK Finder to Symfony 1.3/1.4

Category: Admin Generator,PluginsJeff @ 10:23 am
      

I stumbled all over the place trying to do this. My first stumble was the the Symfony CKEditor plugin was not a stable release. But rather than tell you everything I stumbled on, I’ll just give you the run down on how I got these working via a step-by-step tutorial:

  1. From the plugin page, download the most recent release to your server.  In my case it was 0.1.2 and I put it in my data directory:
    wget http://plugins.symfony-project.org/get/sfCKEditorPlugin/sfCKEditorPlugin-0.1.2.tgz
  2. Install the plugin from the local location on the server:
    symfony plugin:install data/sfCKEditorPlugin-0.1.2.tgz
  3. Download and extract the CKEditor and CKFinder tarball files to your web/js directory.  This creates two new directories, namely web/js/ckeditor and web/js/ckfinder.
  4. Create/edit your project’s config/autoload.yml file to read:
    autoload:
      ckeditor:
        name:       ckeditor
        path:       %SF_WEB_DIR%/js/ckeditor/
        recursive:  on
    
      ckfinder:
        name:       ckfinder
        path:       %SF_WEB_DIR%/js/ckfinder/
        recursive:  on
  5. Edit your application’s config/app.yml file to read:
    all:
      ckeditor:
        basePath:         '/js/ckeditor/'
      ckfinder:
        basePath:         '/js/ckfinder/'
  6. Include the javascript files in your application’s config/view.yml file:
    javascripts:    [/js/ckeditor/ckeditor.js, /js/ckfinder/ckfinder.js]
  7. Enable CKFinder via your application’s configuration class file, within the configure() method:
    class yourappConfiguration extends sfApplicationConfiguration
    {
    	public function configure()
    	{
    		sfConfig::set('app_ckfinder_active', true);
    	}
    }
  8. Enable CKFinder for the current user.  This step will require you to implement your own security method to do properly, but essentially you need to edit the CheckAuthentication() function in the web/js/ckfinder/config.php file so that it returns a true value.  Be careful on this one.  Read the comments in that function and do it right!
    function CheckAuthentication()
    {
    	// WARNING : DO NOT simply return "true". By doing so, you are allowing
    	// "anyone" to upload and list the files in your server. You must implement
    	// some kind of session validation here.
    
    	//this is just a sample function call... create your own
    	if (current_user_is_authenticated()) {
    		return true;
    	} else {
    		return false;
    	}
    }
  9. Clear your Symfony cache:
    symfony cc
  10. A simple form setup should do the trick now:
    $this->widgetSchema['filed_to_enhance'] = new sfWidgetFormCKEditor();

The above should work for both a simple CRUD generation as well as the admin generator.

2 Responses to “Adding CKEditor & CK Finder to Symfony 1.3/1.4”

  1. farai madzima says:

    Peace,

    This got me up and running real quick. But i got stuck on getting the html into the template.

    After a quick search, I found that to output HTML to the template I had to use:

    echo $obj->getValue(ESC_RAW)

    instead of

    echo $obj->getValue()

  2. Matt Farmer says:

    What did you to for your implementation of current_user_is_authenticated()?
    -Matt

Leave a Reply