Modules: Bake modules for XOOPS with CakePHP
Posted by: kiangOn 2007/11/24 23:56:58 9628 readsThis 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 = dirname( dirname(dirname( dirname( __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-align: center;
white-space: nowrap;
}
td.actions a {
display: inline;
margin: 0px 6px;
}
.cakeSqlLog table {
background: #f4f4f4;
}
.cakeSqlLog td {
padding: 4px 8px;
text-align: left;
}
/* Paging */
div.paging {
color: #ccc;
margin-bottom: 2em;
}
div.paging div.disabled {
color: #ddd;
display: inline;
}
/* Notices and Errors */
div.message {
clear: both;
color: #900;
font-size: 140%;
font-weight: bold;
margin: 1em 0;
}
div.error-message {
clear: both;
color: #900;
font-weight: bold;
}
div.error em {
font-size: 140%;
color: #003d4c;
}
span.notice {
background-color: #c6c65b;
color: #fff;
display: block;
font-size: 140%;
padding: 0.5em;
margin: 1em 0;
}
/* Actions */
div.index div.actions {
clear: both;
margin-top: .4em;
text-align: left;
}
div.view div.actions {
clear: both;
margin-top: .4em;
text-align: left;
width: 60%;
}
div.actions ul {
margin: 0px 0;
padding: 0;
}
div.actions li {
display: inline;
list-style-type: none;
line-height: 2em;
margin: 0 2em 0 0;
white-space: nowrap;
}
div.actions ul li a {
color: #003d4c;
text-decoration: none;
}
div.actions ul li a:hover {
color: #333;
text-decoration: underline;
}
/* Related */
div.related {
clear: both;
display: block;
}
/* Debugging */
pre.cake-debug {
background: #ffcc00;
font-size: 120%;
line-height: 18px;
margin: 4px 2px;
overflow: auto;
position: relative;
}
div.cake-stack-trace {
background: #fff;
color: #333;
margin: 4px 2px;
padding: 4px;
font-size: 120%;
line-height: 18px;
overflow: auto;
position: relative;
}
div.cake-code-dump pre {
position: relative;
overflow: auto;
}
div.cake-stack-trace pre, div.cake-code-dump pre {
color: #000000;
background-color: #F0F0F0;
border: 1px dotted #606060;
margin: 4px 2px;
padding: 4px;
overflow: auto;
}
div.cake-code-dump pre, div.cake-code-dump pre code {
clear: both;
font-size: 12px;
line-height: 5px;
margin: 4px 2px;
padding: 4px;
overflow: auto;
}
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 = dirname( dirname(dirname( dirname( __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.