Monday, December 8, 2008

Fck Editor embed in tpl style architechture

It is very easy to use FCKeditor in your PHP web pages. All theintegration files are available in the official distributed package.Just follow these steps.Step 1Suppose that the editor is installed in the /FCKeditor/ path of yourweb site.

The first thing to do is to include the "PHP IntegrationModule" file in the top of your page, just like this:include("FCKeditor/fckeditor.php");?>
Step 2

Now the FCKeditor is available and ready to use. So, just insert thefollowing code in your page to create an instance of the editor(usually inside a FORM):
$oFCKeditor = new FCKeditor('FCKeditor1');
$oFCKeditor->BasePath = '/FCKeditor/';
$oFCKeditor->Value = 'Default text in editor';
$oFCKeditor->Create();
?>
"FCKeditor1" is the name used to post the editor data on forms.
Step 3
The editor is now ready to be used. Just open the page in your browserto see it at work.The complete sampleinclude("FCKeditor/fckeditor.php") ;?>

$oFCKeditor = new FCKeditor('FCKeditor1') ;
$oFCKeditor->BasePath = '/FCKeditor/';$oFCKeditor->Value = 'Default text in editor';
$oFCKeditor->Create() ;?>

Handling the posted dataThe editor instance just created will behave like a normal field in a form. It will use the name you've used when creating it (inthe above sample, "FCKeditor1").So, to retrieve its value you can do something like this:

$sValue = stripslashes( $_POST['FCKeditor1'] ) ;

SamplesYou can find some samples on how to use the editor in the "_samples/php" directory of the distributed package.Other infoIf you want to retrieve the resulting HTML instead of outputting itdirectly to the browser (for example if you're using it in a templateengine such as Smarty), you can call the "CreateHtml" method instead:

$output = $oFCKeditor->CreateHtml() ;*

No comments: