Modules: Bake modules for XOOPS with CakePHP

Posted by: kiangOn 2007/11/24 23:56:58 9628 reads
This article will tell you how to build up modules for XOOPS with bake. :)

Enviornments:
Windows XP Pro SP2
XAMPP 1.6.0a / PHP Version 5.2.4
CakePHP 1.2.0.5875 pre-beta
XOOPS 2.0.17.1
PDT 1.0

1. Setup XOOPS in XAMPP, open a project in PDT and point the workspace to the root of XOOPS.
2. Download and exact Cake 1.2, move the cake folder into the root of XOOPS (D:\xampp\htdocs\xoops\cake)
3. Open PDT,
Run -> External Tools -> Open External Tools Dialog
In Program, add one item
Quote:
Name : BakeXOOPS
Main->Location: D:\xampp\php\php.exe
Working Directory: ${workspace_loc:/xoops/cake/console}
Arguments: cake.php bake -working ../../modules/test/


*The name 'test' is the module name you want to build.
4. Execute BakeXOOPS twice to have basic skeleton of cake and setup database for the new module(test).
5. Open http://localhost/xoops/modules/test/ in your browser to see if cake works in test module.
6. Modify xoops/modules/test/webroot/index.php , in the beginning add the following lines:

$xoops_path dirnamedirname(dirnamedirname__FILE__ ))));
    require_once( 
$xoops_path '/mainfile.php' );
    include 
XOOPS_ROOT_PATH."/header.php";


And at the end:

include XOOPS_ROOT_PATH."/footer.php";


7. Modify xoops/modules/test/views/layouts/default.ctp , the results:

global $xoopsTpl;
$xoopsTpl->assign('xoops_module_header'$html->css('cake.generic') . $scripts_for_layout);
if (
$session->check('Message.flash')):
    
$session->flash();
endif;
echo 
$content_for_layout;
echo 
$cakeDebug;


8. Modify xoops/modules/test/webroot/css/cake.generic.css , Try to remove conflict lines , the results:

table tr.altrow td {
    
background#f4f4f4;
}
td.actions {
    
text-aligncenter;
    
white-spacenowrap;
}
td.actions a {
    
displayinline;
    
margin0px 6px;
}
.
cakeSqlLog table {
    
background#f4f4f4;
}
.
cakeSqlLog td {
    
padding4px 8px;
    
text-alignleft;
}

/* Paging */
div.paging {
    
color#ccc;
    
margin-bottom2em;
}
div.paging div.disabled {
    
color#ddd;
    
displayinline;
}

/* Notices and Errors */
div.message {
    
clearboth;
    
color#900;
    
font-size140%;
    
font-weightbold;
    
margin1em 0;
}
div.error-message {
    
clearboth;
    
color#900;
    
font-weightbold;
}
div.error em {
    
font-size140%;
    
color#003d4c;
}
span.notice {
    
background-color#c6c65b;
    
color#fff;
    
displayblock;
    
font-size140%;
    
padding0.5em;
    
margin1em 0;
}
/*  Actions  */
div.index div.actions {
    
clearboth;
    
margin-top.4em;
    
text-alignleft;
}
div.view div.actions {
    
clearboth;
    
margin-top.4em;
    
text-alignleft;
    
width60%;
}
div.actions ul {
    
margin0px 0;
    
padding0;
}
div.actions li {
    
displayinline;
    list-
style-typenone;
    
line-height2em;
    
margin0 2em 0 0;
    
white-spacenowrap;
}
div.actions ul li a {
    
color#003d4c;
    
text-decorationnone;
}
div.actions ul li a:hover {
    
color#333;
    
text-decorationunderline;
}

/* Related */
div.related {
    
clearboth;
    
displayblock;
}

/* Debugging */
pre.cake-debug {
    
background#ffcc00;
    
font-size120%;
    
line-height18px;
    
margin4px 2px;
    
overflowauto;
    
positionrelative;
}
div.cake-stack-trace {
    
background#fff;
    
color#333;
    
margin4px 2px;
    
padding4px;
    
font-size120%;
    
line-height18px;
    
overflowauto;
    
positionrelative;
}
div.cake-code-dump pre {
    
positionrelative;
    
overflowauto;
}
div.cake-stack-trace prediv.cake-code-dump pre {
    
color#000000;
    
background-color#F0F0F0;
    
border1px dotted #606060;
    
margin4px 2px;
    
padding4px;
    
overflowauto;
}
div.cake-code-dump prediv.cake-code-dump pre code {
    
clearboth;
    
font-size12px;
    
line-height5px;
    
margin4px 2px;
    
padding4px;
    
overflowauto;
}
div.cake-code-dump span.code-highlight {
    
background-color#FFFF00;
}


9. Modify xoops/modules/test/config/database.php , the results:

if(!isset($xoopsOption)) {
    
$xoopsOption['nocommon'] = 1;
    
$xoops_path dirnamedirname(dirnamedirname__FILE__ ))));
    require_once( 
$xoops_path '/mainfile.php' );
}
define('CAKE_DB_PREFIX'XOOPS_DB_PREFIX '_');
class 
DATABASE_CONFIG {

    var 
$default = array(
        
'driver' => XOOPS_DB_TYPE,
        
'persistent' => false,
        
'host' => XOOPS_DB_HOST,
        
'port' => '',
        
'login' => XOOPS_DB_USER,
        
'password' => XOOPS_DB_PASS,
        
'database' => XOOPS_DB_NAME,
        
'schema' => '',
        
'prefix' => CAKE_DB_PREFIX,
        
'encoding' => ''
    
);
}


10. Modify xoops/modules/test/config/core.php

Disable this setting:
Configure::write('Session.start'true);


11. Modify the cache setting in xoops/modules/test/config/core.php

Cache::config('default',array(
    
'engine' => 'File',
    
'path' => XOOPS_ROOT_PATH '/cache',
    
'prefix' => 'cake_'
    
));


12. Modify xoops/cake/libs/cache/file.php
Disable line 79:
$this->settings['path'] = $this->__File->Folder->cd($this->settings['path']);


13. Then you could start baking modules. :)

Known problems:
1. In xoops_version.php of the module, I can't use $modversion['sub'] to add submenu as other modules of XOOPS.
2. Sometimes I met blank page, switch the debug setting or refresh the page could bring me correct results.
3. I can't turn on the debug settings in both at the same time.
4. I met many problems about variable scope, it's not the same as building XOOPS modules like past.
5. "Never" using the results in production without taking care more, more, ... and more.