Revision [17398]

This is an old revision of WikkaCake made by BrianKoontz on 2007-08-11 22:22:23.

 

Integrating Wikka and CakePHP


Why use both?

I advocate the use of Wikka as a FlexibleWikka presentation framework for rapid development of Internet-based applications. Wikka does a great job of handling user authentication, session tracking, and presentation, but does not offer much in the way of easily customizable, high-level database read/write access. Enter CakePHP: A rapid-development PHP framework that handles many of the low-level DB access details so you don't have to. While Cake itself offers similar framework functionality as Wikka, my goal was to implement a totally self-contained Cake application within Wikka. The look-and-feel would be all Wikka, while the Cake engine would provide a database abstraction layer independent of Wikka.

In addition, I'm a big fan of the MVC (model-view-controller) architecture, as it helps with cleanly delineating database functionality, business logic, and presentation. Cake is based upon the MVC (3-tier) model, while Wikka is better classified as a 2-tier model (database and business logic represented by one layer, presentation by the other). It's my belief that Cake could be used as a "plugin" framework that Wikka so badly needs. What follows is my proof of concept of one such implementation.

Goals

The goals for this project were simple:

I believe the first three goals have been met (and my three dogs are still happy with me, so I'm confident goal #4 was met as well).

Project platform

My development environment consists of Mac OSX 10.3.9, running the latest WikkaSVN trunk version of Wikka. The Cake version I'm currently using is 1.1.16.5421. Please be aware that Cake versions starting with 1.2 have significant API changes that may not be compatible with the setup instructions that follow. I have not tested this setup on Wikka 1.1.6.3 or earlier, but other than some directory restructuring, I see no reason why these instructions won't be applicable to earlier Wikka versions.

It's almost a certainly that mod_rewrite MUST be enabled AND operational. This is because Cake (much like Wikka) depends upon the structure of the URL to determine what action gets called. Since both Cake and Wikka (when mod_rewrite is enabled) depend on the same mechanism, there is an inherent conflict that must be resolved by some creative tinkering with the Cake dispatch mechanism. If that was just a bunch of Greek to you, trust me on this: You'll want mod_rewrite enabled!

Installing Cake

Download the latest 1.1.x version of Cake and use whatever method is appropriate for your system to unzip/untar the Cake distribution to your 3rdparty/plugins directory. As a matter of convenience, Unix/OSX users may want to either create a symlink to the cake distribution directory:

ln -s ./cake_1.1.16.5421 cake


or simply rename the directory:

mv cake_1.1.16.5421 cake


Windows users will have to opt for choice #2, as Windows does not support symlinks.

Cake is distributed with its own CSS stylesheet; many of the selectors conflict with the Wikka CSS selectors. As you will see shortly, there is a method that can be invoked in Wikka to include an external stylesheet in the <head> section that's generated by Wikka. I would recommend, at a minimum, that the Cake default CSS file (located at 3rdparty/plugins/cake/app/webroot/css/cake.generic.css) be copied to your Wikka css directory. Then, delete all sections but the section marked .

(If you decide you don't want to do this, there's a strong likelihood you will not see the error messages generated by the Cake built-in data validation methods!)

Setting up a Cake application as a Wikka action

Much of the agony involved with any customized Cake application involves the correct configuration of directories. Wikka itself is also very directory-oriented, so it's doubly important to get this right. There are probably any number of ways this can be accomplished, so my way is not necessarily the only or the best way.

The app directory under your 3rdparty/plugins/cake directory contains everything you need to get started. So, the easiest thing to do is simply copy the contents of the app directory into the new directory you've created for your action. For instance, if your new action will be called "caketest", then you'll first want to create that directory under actions. Then, copy the contents of 3rdparty/plugins/cake/app into this newly-created directory.

For Unix/OSX users:

mkdir actions/caketest
cp -pR 3rdparty/plugins/cake/app/* actions/caketest/


If you've done this correctly, there should not be a directory named app under actions/caketest! If there is, your action will not work correctly under Wikka.

Wikka expects a PHP file under actions/caketest with the name of caketest.php. Simply copy actions/caketest/index.php to actions/caketest/caketest.php.

The normal entry point for a Cake application is webroot/index.php. You'll notice that actions/caketest/index.php redirects to this webroot file. The webroot index.php file is where initial Cake configuration is accomplished, so setting this up correctly is critical.

Here are the steps you need to take. Other than creating your Cake application, this is probably the most complex process involved with Wikka/Cake integration. All of the following steps involve changes to webroot/index.php unless otherwise specified. I recommend making a copy of this file as a backup you can refer to if you get lost.

Locate the line beginning with define('ROOT'...), comment it out, and create a new line:

//define('ROOT', dirname(dirname(dirname(__FILE__))));
define('ROOT', dirname(dirname(__FILE__)));


Next, locate the line beginning with define('APP_DIR'...), comment out and modify:

//define('APP_DIR', 'DIRECTORY NAME OF APPLICATION';
define('APP_DIR', '.');


Comment out/modify CAKE_CORE_INCLUDE_PATH:

//define('CAKE_CORE_INCLUDE_PATH', ROOT);
define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(dirname(dirname(__FILE__)))).DS.'3rdparty'.DS.'plugins');


Due to the fact that Cake is running as an embedded app within Wikka, the base URL that Cake creates doesn't take into account the extra directory levels in which the Cake app resides. Therefore, the BASE_URL parameter must be set explicitly. Locate the closing brace, }, immediately after the CAKE_CORE_INCLUDE_PATH line and add the following, replacing the URL with your Wikka's URL used to access the caketest action:

if (!defined('BASE_URL'))
{
	define('BASE_URL', 'http://alabaster.local/wikka-cake/CakeTest');
}







Valid XHTML :: Valid CSS: :: Powered by WikkaWiki