“How to integrate CKEditor + CKFinder with Session CheckAuthentication into CakePHP”

 

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.

In BeamStyle, we use the CakePHP web application framework.  The CakePHP framework is very easy to use and keeps our code clean.  That’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.

To resolve such an issue, the use of external applications is unavoidable.

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.

== Requirements ==

1) CakePHP has already been setup and working. (http://cakephp.org/)

2) CakePHP Authentication has been setup and working inside CakePHP. (http://book.cakephp.org/view/172/Authentication)

== What you need to get ==

1) Download CKEditor (http://ckeditor.com/)

   – I used CKEditor 3.0.1, released on 16 October 2009

2) Download CKFinder (http://ckfinder.com/)

   – I used CKFinder 1.4.1.1, updated 02.10.2009

  

== Instructions ==

1) Extract your CKEditor and CKFinder into your /app/webroot/js/ directory

   It should look like the following:

     /app/webroot/js/ckeditor/

  /app/webroot/js/ckfinder/

2) Setup CKEditor in your view:

 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’s Authentication method (http://book.cakephp.org/view/172/Authentication), first you need to tell your view about the classname for CKEditor.  Let’s use the controller to tell the view about it because we want to follow some engineering ethics and the rules of MVC.

  


  class AdminController extends AppController {

   ...

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

  

   $ckeditorClass = 'CKEDITOR';

   $this->set('ckeditorClass', $ckeditorClass);

   ...

  }

 b) Since you will be integrating the CKFinder very soon when CKEditor is complete, let’s also define what’s required by CKFinder now, so we save some trouble later :p  The following specifies the path to the CKFinder application.

 

  class AdminController extends AppController {

   ...

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

  

   $ckeditorClass = 'CKEDITOR';

   $this->set('ckeditorClass', $ckeditorClass);

   

   $ckfinderPath = 'js/ckfinder/'

   $this->set('ckfinderPath', $ckfinderPath);

   ...

  }

c1) Now you need to link the javascript libraries for CKEditor and CKFinder into your template (for this example, let’s use the default template -> default.ctp)

 echo $javascript->link('ckeditor/ckeditor.js');

 echo $javascript->link('ckfinder/ckfinder.js'); 

 c2) Now you need to add a CakePHP textarea in your view.  So add it!  And let’s call it “newsContent” for now

 

  [app/views/admin/index.ctp]

  <?php echo $form->textarea('newsContent', array('class'=>$ckeditorClass)) ?>

c3) Now let’s edit the ckfinder’s config.php file so that everything will link perfectly 😉

$baseUrl = ‘upload/’;

$baseDir = '/home/cakeroot/app/webroot/upload/';

 d) If you give a load on that page, you will see a crappy textarea in your page.

    You want to need to convert that into the trendy CKEditor!  And let’s add some default text to it too! XD

    So what you do is you assign a javascript variable to represent ur newsContent, and we called it “ck_newsContent”.

    After that, we set the contents of it using that variable.

  

  [app/views/admin/index.ctp]

  <?php echo $form->textarea('newsContent', array('class'=>$ckeditorClass)) ?>

  

  <script type="text/javascript">

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

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

  </script>

ckeditor_wysiwyg

 

 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 “Server Browser” button)

ckeditor_image

f) So what is that server browser button?  Well, that is in fact the CKFinder.  Let’s add that!

  

  [app/views/admin/index.ctp]

  <?php echo $form->textarea('newsContent', array('class'=>$ckeditorClass)) ?>

  

  <script type="text/javascript">

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

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

  CKFinder.SetupCKEditor( ck_newsContent, '<?php echo $ckfinderPath ?>') ;

  </script>

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 >__<

ckfinder_restrict

h) Yes that’s right.  You need authentication check!  Let’s do that!

 Open up app/webroot/js/ckfinder/config.php

And first thing, implement your CheckAuthentication() function, like the following:

function CheckAuthentication()

{

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

 {

  return true;

 }

 return false;

}

i) Now, because CakePHP uses a different session name (Not the default name), we gotta tell CKFinder to look inside THAT CAKEPHP SESSION!

 

 Add the following at the very top of the config.php file, right below <?php

<?php

// Start CakePHP Session

session_name("CAKEPHP");

session_start();

j) Let’s but not least, let’s add an upload folder and grant 757 Permissions to it:

->  app/webroot/upload

 

ckfinder_allow

k) Now try loading up the Server Browser rom step (g) again and happy surfing!

Many people do not understand the differences between Yahoo! Store and a self-hosted e-commerce solution such as Prestashop. Both solution has its own advantages and disadvantages. Some customers ask us whether they need a self-hosted e-commerce solution or not. I always tell them that it really depends on what their needs are. In general, if our customers are unsure of their sales target and just want to open a store, I would recommend them to first use a simplier solution such as Yahoo! Store to test the market. Otherwise, I believe a self-hosted e-commerce solution will save more money in the long run. Here is a simple comparison of the two solutions.

Feature Yahoo! Store Self-hosted e-commerce solution
Cost Yahoo! Store costs around $400 HKD for the initial setup fee. In addition, for its starter package, it has a monthly fee of around $320 HKD and a 1.5% transaction fee (does not include credit card payment or Paypal payment fees). For its professional package, it costs around $2400 HKD monthly and a 0.75% transaction fee. A self-hosted e-commerce solution has a one time setup fee (which includes web site design and programming fee) which is significantly higher than the Yahoo! store (depending on the functionality). In addition, there is a server cost to host the solution. There are no hidden fees.
Design Somewhat customizable, but it requires a programmer and graphics designer to do it (cost depends on the rate of the design team). Fully customizable, and the cost is already included in the solution package.
Reliability Depends on Yahoo!’s server uptime Depends on the hosted server uptime (you must ask yoru server provider what is its guarantee uptime)
Functionality Limited to what Yahoo! offers to its customers (cannot add new functionalities) Fully customizable (for example, you can integrate the shop’s user account system to an existing user database)
Ownership The shop is hosted on Yahoo and it belongs to Yahoo.  You cannot easily move your shop to another provider. The shop belongs to you, you can open the shop on several different web sites without paying anything extra (except for server fee).
Performance Depends on the performance of Yahoo! Depends on the hosted server (you can choose the location of the server.  For example, if your shop is opened in HK, then you can get a server in Hong Kong to get optimum speed)



how to get back your girl
do you ever miss your ex when on holiday
i cheated boyfriend wont take me back
win back my boyfriend after a month break up
how to get back with your ex boyfriend after you broke up

Tonight, I went to the supermarket and I wanted to check the number of points my supermarket cards has. I was greeted by this mess. Wow.

i have a holiday booked with my ex girlfriend what should i do.

what the best advice to get someone back

how to handle if your ex trys to return after a breakup

how to get man back after breakup

how to getover ex husband

my ex bf friends are my friends

tips to get back my long distance boyfriend

how to get back your ex girlfriend when you broke up with her

how do i know if my ex wants to get back together with me

ex boyfriend text you

How to get an ex gilrfriend back

my boyfriend broke up with me why doesnt he want me back

things to say to make your girlfriend get back with you

he left me for another woman i want him back how

does ex girlfriend going to dinner with you mean she still loves you

how can i get my ex back but we are distance away

how to make him get back with me

my ex back

how to make your ex man want you back

How to get your man back after broke up
http://blog.beamstyle.com.hk/wp-content/uploads/2009/02/shopping-machine.jpg” alt=”A point card machine with a mess in front of it.” width=”375″ height=”500″ /> A point card machine with a mess in front of it.

You may think this is wierd, but actually there are so many websites which does similar things.

Continue reading

Table2CSS Converter Box

A couple days ago, I was given a task to convert a webpage using HTML tables for positioning to a webpage using CSS for positioning. I was rather lazy and I looked for a free tool to do this task. After looking up in Google for a few minutes, I found this software called Table2CSS Converter. This software is actually quite user friendly to use. All you have to do is to specify a folder to convert and it’s all done for you.

Continue reading