The day I learned CakePHP, it started inspiring me for getting more and more out of it. Its custom hacks are pretty cool, and CakePHP is a complete framework in itself. However, like all other frameworks, it creates too much of work when we have to code some features again and again, like User-registration, a link manager, gallery and all.... Joomla does handle all this pretty well. So, after I saw Drake, I decided to write my same thing with Joomla as I like it as a CMS and it is used by us everyday.
I would like to thank Felix from ThinkingPHP the most, his research helped me a lot to do this.
Let's start with a nice fresh setup.
1) Download Fresh versions of Cake and Joomla
and install Cake first (for me its joomla_cake), Rename cakephp's /app/webroot/index.php to cakephp.php then install Joomla inside 'webroot' of Cake's directory.
So your directory structure will be like:
/app
---------/webroot
-----------------/joomla's index.php with other files
-----------------/cakephp.php (we will use this to triger Cake)
/cake
/vendors
Edit cakephp.php
-
{
-
}
-
else
-
{
-
/* $Dispatcher= new Dispatcher ();
-
$Dispatcher->dispatch($url);*/
-
}
Now we have disabled page rendering if we include this 'cakephp.php' in any external application.
2) Lets Create Joomla Component which will trigger Cake. : Lets call it 'com_cake'. This will be our master component in Joomla which will be triggered in case of when any unidentified Joomla's component is called... Lets add this functionality first.. Edit Joomla's index.php:
-
//Before Joomla initialize its mainframe, lets play...
-
// check missing component -- added before $mainframe is being initialized
-
//##########################
-
$option='com_cake'; //set component to com_cake if a controller is not found.
-
//##########################
-
$mainframe = new mosMainFrame( $database, $option, '.' );
Lets get back to create the component:
/app
---------/webroot
-----------------/components (Joomla's component dir)
------------------------/com_cake
----------------------------------/cake.html.php (trigger to cakephp)
----------------------------------/cake.php (calls trigger with required options)
/cake
/vendors
We have to follow Joomla conventions for this module...
Lets create these 2 files, cake.php and cake.html.php:
cake.html.php:
cake.php: This file will judge which controller/action to pass in cakephp.
-
require_once($mainframe->getPath('front_html'));
-
$mainframe->setPageTitle("Check this out");
-
global $database;
-
$controller=mosGetParam( $_REQUEST ,'option'); //option passed is treated as a controller in cake
-
$action=mosGetParam( $_REQUEST ,'task'); //task passed is treated as a controller in cake
-
HTML_cake::requestCakePHP('/'.$controller.'/'.$action);
3) Time to check its functioning:
www.myserver.com/joomla/index.php?option=names&task=add
1. $_GET['option'] is passed to Joomla's index.php. There it concluded that component called 'names' is not found, so lets pass it to 'com_cake'
2. Now we are in cake.php (com_cake), we will check what controller and action it is requesting, and trigger the 'requestCakePHP' function.
This will make Joomla to assume that component being called is 'com_cake', and task is 'names/add'. This task will be then passed to Cake as $_GET['url'].
And we're done...
I see baked code of Cake's model 'name' inside Joomla.
Currently, I have not created it to handle the function arguments... but if I found this to be more useful... I will continue the project. The next updates will be:
1. Better handling of function arguments.
2. Customization of CakePHP's helpers to make use of right path and more.
3. Utilization of some plugins
Thanks
-- Max aka Abhimanyu Grover