Tuesday 22 February 2011

Make FckEditor Plugin In Codeigniter


I just try how to use Fckeditor as a Library in CI.It’s indeed simple but in the wiki ( http://codeigniter.com/wiki/FCKeditor/ ) it’s hard to understand witch updates to do for the last CI version (1.7.1). Here what I do step by step.


  1. Download Fckeditor.

  1. Extract the folder "fckeditor" in "system/plugins/"

  1. Open the "fckeditor" folder and copy the file "fckeditor.php"

  1. Past the file in "system/application/libraries"

  1. Edit the file you just past and add this line to the top


if (!defined('BASEPATH')) exit('No direct script access allowed');


  1. In the same file now change the path of the include to have something like


if ( !function_exists('version_compare') || version_compare( phpversion(), '5',
'<' ) )
    include_once( 'system/plugins/fckeditor/fckeditor_php4.php' ) ;
else
    include_once( 'system/plugins/fckeditor/fckeditor_php5.php' ) ;


  1. Open the file "system/plugins/fckeditor/fckeditor_php5.php" and add this line to the top



if (!defined('BASEPATH')) exit('No direct script access allowed');


  1. Change this part of the class

    class FCKeditor

    {

    public $InstanceName ;


    public $BasePath ;

    public $Width ;

    public $Height ;

    public $ToolbarSet ;

    public $Value ;


    public $Config ;

    public function __construct( $instanceName )

    {

    $this->InstanceName = $instanceName ;


    $this->BasePath = '/fckeditor/' ;

    $this->Width = '100%' ;

    $this->Height = '200' ;


    $this->ToolbarSet = 'Default' ;

    $this->Value = '' ;

    $this->Config = array() ;


    }

    ...

    into this





class Fckeditor
{
    var $InstanceName ;
    var $BasePath ;
    var $Width ;
    var $Height ;
    var $ToolbarSet ;
    var $Value ;
    var $Config ;
    public function __construct( $array )
     {
        $this->InstanceName = $array['instanceName'] ;
        $this->BasePath        = $array['BasePath'] ;
        $this->Width        = $array['Width'] ;
        $this->Height        = $array['Height'] ;
        $this->ToolbarSet    = $array['ToolbarSet'] ;
        $this->Value        = $array['Value'] ;
        $this->Config        = array() ;
    }

...

open the fckeditor_php4.php and add the same line to the top and rename the class name into "class Fckeditor"

  1. In your controller you should have something like


function fckeditorform(){
   $fckeditorConfig = array(
          'instanceName' => 'content',
          'BasePath' => base_url().'system/plugins/fckeditor/',
          'ToolbarSet' => 'Basic',
          'Width' => '100%',
          'Height' => '200',
          'Value' => ''
            );
   $this->load->library('fckeditor', $fckeditorConfig);
   $this->load->view('fckeditorView');
}
function fckeditorshowpost(){
        echo $this->input->post('content');
}


  1. In your view you should have something like


$this->load->helper('form');
echo '<h1>FckEditor</h1>';
echo form_open('yourcontroller/fckeditorshowpost');
echo $this->fckeditor->Create() ;
echo form_submit(array('value'=>'submit'));
echo form_close();

No comments:

Post a Comment