Jake 2.0 Released

In 2009 I posted an enhancement to the Jake Joomla component that allowed for the use of ordinary CakePHP URL’s to enhance readability and SEO.  However, the component only worked for the current stable versions of CakePHP and Joomla (1.3 and 1.5, respectively).  Since then, there have been major upgrades to both those projects and after much work I am pleased to announce the release of Jake 2.0, which supports the latest stable versions as of this writing: CakePHP 2.2.2 and Joomla 2.5.0.  This has been tested on PHP 5.3.6 and Apache 2.2.

As with the previous version, you can run the CakePHP app separately, via its own VirtualHost, or inside Joomla, without any significant code changes to either.

 

Update 12/27/12 – The component has been updated for Joomla 3.0 and published to github.

 

Setup Steps

The server configuration has changed to allow for cleaner separation of the CakePHP and Joomla codebases.  Previously the CakePHP app install was underneath the Joomla webroot, which would make upgrading either project difficult, cause headaches with source-control, etc.  Now, the CakePHP directory should be a sibling to the Joomla one, i.e.,

/path/to/www/joomla-cms (your JOOMLA_ROOT)
/path/to/www/cakephp (your CAKEPHP_ROOT)

This will allow you to, for example, upgrade Joomla and CakePHP independently at any time. Much better.

  1. Add the following Apache Alias, used for delivering existing files from under CAKEPHP_ROOT/app/webroot, to the Joomla VirtualHost. This should point to the app/webroot directory of the CakePHP app.
    Alias /webapp "CAKEPHP_ROOT/app/webroot"
    <Directory "CAKEPHP_ROOT/app/webroot">
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>
  2. Bounce Apache.
  3. Update CAKEPHP_ROOT/index.phpto make the following changes:
    [...]
    define('APP_DIR', 'app');
     
    // Make sure it's not already defined...
    if (!defined('DS'))
       define('DS', DIRECTORY_SEPARATOR);
    define('ROOT', dirname(__FILE__));
    [...]
  4. Update CAKEPHP_ROOT/app/webroot/index.phpto make the following changes:
    [...]
    //define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
     
    // Modified from Cake/bootstrap.php so we can pre-define FULL_BASE_URL here instead.
    if (defined('JAKE')) {
    $s = null;
    if (isset($_SERVER['HTTPS'])) {
       $s = 's';
    }
     
    $httpHost = $_SERVER['HTTP_HOST'];
     
    if (isset($httpHost)) {
       define('FULL_BASE_URL', 'http' . $s . '://' . $httpHost . '/app');
    }
    unset($httpHost, $s);
    }
     
    /**
    * Editing below this line should NOT be necessary.
    * Change at your own risk.
    *
    */
     
    [...]
     
    App::uses('Dispatcher', 'Routing');
     
    $Dispatcher = new Dispatcher();
    $r = new CakeRequest();
     
    if (defined('JAKE'))
    {
       $r->url = $url;
       $r->here = $url;
       unset($url);
    }
    $Dispatcher->dispatch($r, new CakeResponse(array('charset' => Configure::read('App.encoding'))));
  5. If you have upgraded to Joomla 2.5 from a previous 1.5 version that had the previous Jake component installed (which obviously stopped working when you upgraded), uninstall Jake.  In addition, you’ll need to manually remove the Jake menu links from the database (which in my experience were not deleted upon uninstall).  To do this, execute the following, replacing your Joomla table prefix as appropriate:
    DELETE FROM `[TABLE_PREFIX]_menu` WHERE `link` LIKE '%jake%';
  6. Install the new Jake component via the Joomla Extension Manager: com_jake-2.0.0.zip.  See the update above regarding github.
  7. Update JOOMLA_ROOT/.htaccessas follows:
    [...]
    ## Begin - Custom redirects
    #
    # If you need to redirect some pages, or set a canonical non-www to
    # www redirect (or vice versa), place that code here. Ensure those
    # redirects use the correct RewriteRule syntax and the [R=301,L] flags.
    #
     
    # For Jake, we need to handle everything that starts with "app"
    # See http://www.phpbb-seo.com/en/apache-mod-rewrite/article3226.html and http://blog.echothis.com/2009/07/22/search-engine-friendly-urls-using-the-jake-bridge/
     
    # First, redirect any static assets to /webapp/* as per http://www.askapache.com/htaccess/setenvif.html
    # Note use of (.+) to make sure that /app/ itself is skipped here
     
    SetEnvIfNoCase  REQUEST_URI "\/app\/(.+)$"  path_to_check=cakephp/app/webroot/$1
     
    # Make sure that path_to_check is not empty
    RewriteCond     %{ENV:path_to_check} ^(.+)$
     
    RewriteCond     %{DOCUMENT_ROOT}/../%{ENV:path_to_check} -f                     [OR]
    RewriteCond     %{DOCUMENT_ROOT}/../%{ENV:path_to_check} -d
    RewriteRule     ^app\/(.*)$     /webapp/$1                                      [QSA,L]
     
    # And finally, handle everything remaining as an ordinary Cake action
    RewriteRule ^app(.*)$ /index.php?option=com_jake&amp;jrun=$1 [QSA,L]
     
    ## End - Custom redirects
    [...]

Now you can access your CakePHP app inside Joomla at the URL http://yourserver/app, using the latest and greatest versions of Cake and Joomla.

8 comments

  1. Hi There,

    When trying to install I get this error JInstaller: :Install: File does not exist /var/www/joomla/tmp/jake/admin/lib/bootstrap.php.

    In the jake.XML is looks like you are missing some files:
    lib/bootstrap.php
    lib/cake_embedded_dispatcher.class.php
    lib/constants.php
    lib/jake_component.class.php
    lib/jake.class.php
    views/send/tmpl/default.php
    views/send/view.html.php
    jake_front_component.class.php
    jake_front_controller.class.php
    jake.html.php
    jake.ini
    jake.php

    Any ideas?

    Thanks

    Michael

  2. Hello, and thanks for letting us know your tips and tricks.

    My question boils down to this:
    will I be able to call cakePHP and joomla from my app?
    Are both parsers in place without interfering?

    My idea (just working on it in winter times though):
    a simple CRUD done by cakePHP accessible by joomla users.

    Thanks a lot!

  3. Yes, the idea is that the two codebases are completely decoupled and do not interfere at all. So you can develop your CakePHP site independently, and run it either inside, or outside, Joomla. You have full access from the CakePHP side to the Joomla classes via JFactory(), and can conditionally check for whether you’re running inside Joomla via defined('JAKE').

    For example, I have multiple virtual hosts running on my machine, so I have a normal CakePHP installation at http://localhost:96 and a normal Joomla one at http://localhost:93. Using the configuration steps here I then have CakePHP running inside Joomla at http://localhost:93/app.

  4. Hello and thanks for your time.

    I’m trying to Jakeif without success. :/
    Can you help me ?

    my folder structure is:
    c:/wamp/www/cakephp
    c:/wamp/www/joomla

    my alias config:

    Alias /webapp "c:/wamp/www/cakephp/app/webroot/"

    AllowOverride All
    Order allow,deny
    Allow from all

    All same to the tutorial !!!

    When i put url
    1) http://localhost/joomla/app –> show me the localhost page

    2) http://localhost/app/ –> show me a cake error

    (Missing Method in AppController)
    Error: The action index is not defined in controller AppController

    3) http://localhost/joomla/index.php?option=com_jake&jrun=CakeController –> show me the cake application, but the links and submit not work

    Have any idea ?

    Thanks and sorry for poor english

Leave a comment

Your email address will not be published. Required fields are marked *