<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Technical Entrepreneur &#187; Thomas</title>
	<atom:link href="http://blog.beamstyle.com.hk/author/thomas/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.beamstyle.com.hk</link>
	<description>Web Design and Marketing Tips</description>
	<lastBuildDate>Sat, 16 Oct 2010 14:30:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Tutorial on integrating CKFinder/CKEditor into CakePHP with session CheckAuthentication.</title>
		<link>http://blog.beamstyle.com.hk/tutorial-on-integrating-ckfinderckeditor-into-cakephp-with-session-authentication/</link>
		<comments>http://blog.beamstyle.com.hk/tutorial-on-integrating-ckfinderckeditor-into-cakephp-with-session-authentication/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 04:23:15 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Java Programming]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Website Design]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[CheckAuthentication]]></category>
		<category><![CDATA[CKEditor]]></category>
		<category><![CDATA[CKFinder]]></category>
		<category><![CDATA[File Manager]]></category>
		<category><![CDATA[Image Upload]]></category>
		<category><![CDATA[Session]]></category>

		<guid isPermaLink="false">http://blog.beamstyle.com.hk/?p=170</guid>
		<description><![CDATA[
&#8220;How to integrate CKEditor + CKFinder with Session CheckAuthentication into CakePHP&#8221;
 
In the process of web development such as CMS (Content Management System), there are many cases where you may find a WYSIWYG editor or a file manager useful.  However from my experience, I noticed that most web application frameworks provide from crappy to no backend [...]]]></description>
			<content:encoded><![CDATA[<p><strong></p>
<h1><font color=#000000>&#8220;How to integrate CKEditor + CKFinder with Session CheckAuthentication into CakePHP&#8221;</font></h1>
<p> </p>
<p></strong>In the process of web development such as CMS (Content Management System), there are many cases where you may find a WYSIWYG editor or a file manager useful.  However from my experience, I noticed that most web application frameworks provide from crappy to no backend interface for WYSIWYG editors or file managers or uploading functions.</p>
<p>In BeamStyle, we use the CakePHP web application framework.  The CakePHP framework is very easy to use and keeps our code clean.  That&#8217;s the reason why we are using it.  But of course, nothing is perfect.  The form filling API is crappy and there is no file management system.</p>
<p>To resolve such an issue, the use of external applications is unavoidable.</p>
<p>In this tutorial, I will introduce the method on how to setup CKEditor (WYSIWYG editor) and CKFinder (File Manager, Upload) with CakePHP with CakePHP Authentication.</p>
<p>== Requirements ==</p>
<p>1) CakePHP has already been setup and working. (<a href="http://cakephp.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://cakephp.org/');">http://cakephp.org/</a>)</p>
<p>2) CakePHP Authentication has been setup and working inside CakePHP. (<a href="http://book.cakephp.org/view/172/Authentication" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://book.cakephp.org/view/172/Authentication');">http://book.cakephp.org/view/172/Authentication</a>)</p>
<p>== What you need to get ==</p>
<p>1) Download CKEditor (<a href="http://ckeditor.com/" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://ckeditor.com/');">http://ckeditor.com/</a>)</p>
<p>   &#8211; I used CKEditor 3.0.1, released on 16 October 2009</p>
<p>2) Download CKFinder (<a href="http://ckfinder.com/" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://ckfinder.com/');">http://ckfinder.com/</a>)</p>
<p>   &#8211; I used CKFinder 1.4.1.1, updated 02.10.2009</p>
<p>  </p>
<p>== Instructions ==</p>
<p>1) Extract your CKEditor and CKFinder into your /app/webroot/js/ directory</p>
<p>   It should look like the following:</p>
<p>     /app/webroot/js/ckeditor/</p>
<p>  /app/webroot/js/ckfinder/</p>
<p>2) Setup CKEditor in your view:</p>
<p> a) Assuming that you already have your form and Javascript enabled in your controller, and your controller is named AdminController, and your Admin view is already password protected by CakePHP&#8217;s Authentication method (<a href="http://book.cakephp.org/view/172/Authentication" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://book.cakephp.org/view/172/Authentication');">http://book.cakephp.org/view/172/Authentication</a>), first you need to tell your view about the classname for CKEditor.  Let&#8217;s use the controller to tell the view about it because we want to follow some engineering ethics and the rules of MVC.</p>
<p>  
<pre>

  class AdminController extends AppController {

   ...

   var $helpers = array('Form', 'Html', 'Javascript', 'Time');

  

   $ckeditorClass = 'CKEDITOR';

   $this-&gt;set('ckeditorClass', $ckeditorClass);

   ...

  }
</pre>
<p> b) Since you will be integrating the CKFinder very soon when CKEditor is complete, let&#8217;s also define what&#8217;s required by CKFinder now, so we save some trouble later :p  The following specifies the path to the CKFinder application.</p>
<p> </p>
<pre>
  class AdminController extends AppController {

   ...

   var $helpers = array('Form', 'Html', 'Javascript', 'Time');

  

   $ckeditorClass = 'CKEDITOR';

   $this-&gt;set('ckeditorClass', $ckeditorClass);

   

   $ckfinderPath = 'js/ckfinder/'

   $this-&gt;set('ckfinderPath', $ckfinderPath);

   ...

  }
</pre>
<p>c1) Now you need to link the javascript libraries for CKEditor and CKFinder into your template (for this example, let&#8217;s use the default template -&gt; default.ctp)</p>
<pre>
 echo $javascript-&gt;link('ckeditor/ckeditor.js');

 echo $javascript-&gt;link('ckfinder/ckfinder.js'); 
</pre>
<p> c2) Now you need to add a CakePHP textarea in your view.  So add it!  And let&#8217;s call it &#8220;newsContent&#8221; for now</p>
<p> </p>
<p>  [app/views/admin/index.ctp]</p>
<pre>
  &lt;?php echo $form-&gt;textarea('newsContent', array('class'=&gt;$ckeditorClass)) ?&gt;
</pre>
<p>c3) Now let&#8217;s edit the ckfinder&#8217;s config.php file so that everything will link perfectly <img src='http://blog.beamstyle.com.hk/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>$baseUrl = &#8216;upload/&#8217;;</p>
<pre>
$baseDir = '/home/cakeroot/app/webroot/upload/';
</pre>
<p> d) If you give a load on that page, you will see a crappy textarea in your page.</p>
<p>    You want to need to convert that into the trendy CKEditor!  And let&#8217;s add some default text to it too! XD</p>
<p>    So what you do is you assign a javascript variable to represent ur newsContent, and we called it &#8220;ck_newsContent&#8221;.</p>
<p>    After that, we set the contents of it using that variable.</p>
<p>  </p>
<p>  [app/views/admin/index.ctp]</p>
<pre>
  &lt;?php echo $form-&gt;textarea('newsContent', array('class'=&gt;$ckeditorClass)) ?&gt;

  

  &lt;script type="text/javascript"&gt;

  var ck_newsContent = CKEDITOR.replace( 'newsContent' );

  ck_newsContent.setData( '&lt;p&gt;Just click the &lt;b&gt;Image&lt;/b&gt; or &lt;b&gt;Link&lt;/b&gt; button, and then &lt;b&gt;&amp;quot;Browse Server&amp;quot;&lt;/b&gt;.&lt;/p&gt;' );

  &lt;/script&gt;

<img class="alignnone size-full wp-image-167" title="ckeditor_wysiwyg" src="http://blog.beamstyle.com.hk/wp-content/uploads/2009/11/ckeditor_wysiwyg.jpg" alt="ckeditor_wysiwyg" width="857" height="396" />
</pre>
<p> </p>
<p> e)  Now, if you just load the page and click on the image icon (circled in red in the above image), u will see Image Properties window showing up like below (Except without the &#8220;Server Browser&#8221; button)</p>
<pre>
<img class="alignnone size-full wp-image-166" title="ckeditor_image" src="http://blog.beamstyle.com.hk/wp-content/uploads/2009/11/ckeditor_image.jpg" alt="ckeditor_image" width="326" height="305" />
</pre>
<p>f) So what is that server browser button?  Well, that is in fact the CKFinder.  Let&#8217;s add that!</p>
<p>  </p>
<p>  [app/views/admin/index.ctp]</p>
<pre>
  &lt;?php echo $form-&gt;textarea('newsContent', array('class'=&gt;$ckeditorClass)) ?&gt;

  

  &lt;script type="text/javascript"&gt;

  var ck_newsContent = CKEDITOR.replace( 'newsContent' );

  ck_newsContent.setData( '&lt;p&gt;Just click the &lt;b&gt;Image&lt;/b&gt; or &lt;b&gt;Link&lt;/b&gt; button, and then &lt;b&gt;&amp;quot;Browse Server&amp;quot;&lt;/b&gt;.&lt;/p&gt;' );

  CKFinder.SetupCKEditor( ck_newsContent, '&lt;?php echo $ckfinderPath ?&gt;') ;

  &lt;/script&gt;
</pre>
<p>g) After you add the above code and try again and you will see the button.  If you click on the button, you may find the following restriction screen &gt;__&lt;</p>
<pre>
<img class="alignnone size-full wp-image-169" title="ckfinder_restrict" src="http://blog.beamstyle.com.hk/wp-content/uploads/2009/11/ckfinder_restrict.jpg" alt="ckfinder_restrict" width="519" height="342" />
</pre>
<p>h) Yes that&#8217;s right.  You need authentication check!  Let&#8217;s do that!</p>
<p> Open up app/webroot/js/ckfinder/config.php</p>
<p>And first thing, implement your CheckAuthentication() function, like the following:</p>
<pre>
function CheckAuthentication()

{

 if( isset($_SESSION['Auth']['User']) )

 {

  return true;

 }

 return false;

}
</pre>
<p>i) Now, because CakePHP uses a different session name (Not the default name), we gotta tell CKFinder to look inside THAT CAKEPHP SESSION!</p>
<p> </p>
<p> Add the following at the very top of the config.php file, right below &lt;?php</p>
<pre>
&lt;?php

// Start CakePHP Session

session_name("CAKEPHP");

session_start();
</pre>
<p>j) Let&#8217;s but not least, let&#8217;s add an upload folder and grant 757 Permissions to it:</p>
<p>-&gt;  app/webroot/upload</p>
<p> </p>
<pre>
<img class="alignnone size-full wp-image-168" title="ckfinder_allow" src="http://blog.beamstyle.com.hk/wp-content/uploads/2009/11/ckfinder_allow.jpg" alt="ckfinder_allow" width="633" height="281" />
</pre>
<p>k) Now try loading up the Server Browser rom step (g) again and happy surfing!</p>

]]></content:encoded>
			<wfw:commentRss>http://blog.beamstyle.com.hk/tutorial-on-integrating-ckfinderckeditor-into-cakephp-with-session-authentication/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

