Tutorial

So this Tutorial will show how to configure a Standard drupal and cake installation to work together without modifying the core of either one. In case you are one of the people who just want things to work I recommend downloading the source of this website as a zipped file and just copy it to your local webroot.

Downloads

Prior to getting started you have to download the following packages: Important: This tutorial is only written for Drupal 4.7 Beta 2 and CakePHP 0.10.3.1311_pre_beta. Generally spoken it should work with other versions but I haven't tried it yet. But you can always ask me if you've got any question by posting it in the comments below.

Step 1: Preperation

The first thing you need to know is that the following things are required in order to complete this tutorial:

  • PHP 4.3.x (maybe earlier versions as well)
  • MySql 3.1.x or higher
  • An Apache webserver (mod_rewrite module must be activated!)

The next thing you have to do is to create a new folder called "drake" in your webroot (for me it's "C:\Localhost"). This will be the folder where you are going to put Drupal and also CakePHP in. Then you should extract drupal as "_drupal" and CakePHP as "_cake" into this folder.
After that create a file called ".htaccess" inside of your "/drake" folder. It will contain the information for your Webserver to know who to talk to. Write the following lines of code inside this file:
And the last thing you've got to prepare is to move the drake.module that to the folder "/drake/_drupal/modules" in order to be able to activate it later on.

Step 2: Installing & Setting up Drupal

The first thing you need to do is to create a database for drupal to use. I named mine "drake_db". Then you should use something like phpMyAdmin to import the tables required by drupal. The file you need to import is "/drake/_drupal/database/database.mysql". After successfully importing the sql file you have to configure drupal itself. To do so open the file "/drake/_drupal/sites/default/" and modify the following lines to match your settings:

So now you can access your drupal site by browsing to: "http://localhost/drake/". The first thing you should do there is to click on the link "create the first account" and create the first account which will automatically become an admin account. Don't forget to set up a password for it on the site you get redirected to after you registered!

So now the next thing there is to do is to activate the darke module. In order to do this navigate to "administer >> modules". Then check the checkboxes in front of the module called "drake and click on the "Save configuration" button below.

Now you should make Drupal using mod_rewrite for emitting clean urls. In order to do so navigate to "settings" and open up the stuff that is hidden underneath the entry "General settings". Look for an option that is named "Clean URLs:" and enable it.

Test what you did: If you want to test if you did everything correct to this point try to navigate to an non-existing URL inside of drupal. I used "http://www.localhost/drake/i_dont_exist" in order to test it. At this point you should see the standard "Missing Controller" page from CakePHP. Don't be worried that it doesn't look like Cake is integrated into drupal yet, it's just a question of changing the layout at this point.

Step 3: Setting up CakePHP

The first thing you should do is again, setting up the database. But this time for cake. In order to do so find a file called: "/drake/_cake/app/config/database.php.default" and rename it to "database.php". Open up the renamed file and edit it. The database settings should match the ones for drupal. (Note: I've used drupal and cake with two seperate databases before but it add's more difficulty to it, but if you need it just ask me). Another thing: You might want to change "mysql_pconnect to "mysql_connect since I experienced some problems before with using pconnect.

The next thing is a very important one, since it will make sure nobody uses your cake without drupal baking it ; ). Open up the file: "/drake/_cake/app/webroot/.htaccess" and modify it to look like this:

This step will finally make everything work. Create a file "/drake/_cake/app/webroot/layouts/default.thtml" and put the following code inside of it: (Note: The function use_drupal_layout() rests inside of the drupal.module you copied earlier.)

Done!!! Now you should be able to call "http://www.localhost/drake/i_dont_exist" and see a picture like this:

What now?

Well from this point on there are still a couple things to figure out. For example you need to be aware of the fact that you are using two locations to store informations as pictures, css, js etc. In order make sure everything works properly you might have to go and modify the html helper class so it know that right path (if you want to store everything inside of drupal). The next thing would be the nice breadcrumbs drupal is supporting to show you at what point of the side you are, so you might need to play with them a little bit to make them work with cake. You should also know that you can now use just about any function provided by Drupal see: http://drupaldocs.org/api/head for more information. There is already a ton of cool stuff for drupal like the t() function to translate things or the fact that drupal can work with different theme engines.

So I would like everybody who tried this out to post his feedback in the comments below and tell me what he thinks of this idea or if he needs any help setting it up.

Felix Geisendörfer (Felix Ge [at] web [dot] de)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Drake progress

Since I see that there are people interested in using Drake in production enviornment I'll try to use the next couple of days to get my latest version packed up in a neat package, together with some information on installation and usage.

Check this site and my blog http://www.thinkingphp.org for progess

--Felix Geisendörfer aka the_undefined

Setup problem with Drake/Drupal/Cake

Hi Felix

I am attempting to run Drake with Drupal 4.7.0-beta6 and Cake_0.10.9.2378_final (latest release)

These are more recent releases, especially in the case of Cake, so I am expecting problems. I would be very grateful if you could give me some suggestions with my first hitch:

I have installed and configured as you instruct, except for one change, the final step of creating the default.thtml file.

Rather than putting it in:

/_cake/app/webroot/layouts/default.thtml

/_cake/app/views/layouts/default.thtml

This works fine, however when I test the installation by calling a dummy page name I get the following error:

"Fatal error: Call to undefined function: use_drupal_layout() in /_cake/app/views/layouts/default.thtml on line 1"

So the Cake controller is being invoked correctly, but it can't find the use_drupal_layout() function.

Can you make any guess at why this may be? The Drake module is installed and loaded through the Drupal Admin page. Any suggestions would be greatly appreciated.

Regards,
Langdon

drake update comming soon?

Felix, I would like to know if you have any plans on updating Drake for using it with Cake's current 0.10.4.1922 RC4 release.

Honestly I have not installed your project yet, so maybe I missing if it already works with it (current 0.10.4.1922 RC4) anyway.

I will give it a try with CakePHP 0.10.3.1311_pre_beta and then will try it with current 0.10.4.1922 RC4 and see what happens.

$drake = "Lovely RAD Idea";

A Marriage of Two Great Things

I love Drupal and I'm excited about CakePHP (and RoR as well). You've done a great thing by putting them two together and enabling rapid application development inside Drupal.

Thanks! I will start playing with it soon.

-Camus