[FX.php List] REDO-FX.php as a Library in CodeIgniter framework
DC
dan.cynosure at dbmscan.com
Fri Apr 13 10:29:59 MDT 2007
Hi,
OO-ps... I didn't follow OO practices when submitting my integration
technique. I've redone steps 3, 4, and 5 so that you do not modify
FX.php at all - you simply extend it using PHP's OO capability. The full
instructions with (easier) redone steps follow.
-------------------------------------------
I put together what I think is the cleanest integration possible between
FX.php and CodeIgniter (CI). It's pretty easy to do.
If you are looking for a good way of expanding your PHP horizons,
CodeIgniter is a good way to do it. If you haven't seen CodeIgniter,
head over to http://codeigniter.com to check it out. In short, it is a
PHP Framework that helps you organize code and offers nice integrated
libraries. It is also PHP4 and 5 friendly, highly object-oriented, and
extendable.
I've been testing out FX.php with CI and I like it a lot.
Here's how I got my set up working:
1) Download, install and configure CI per the very good instructions at
the site. If you have problems, the CI forum is helpful. It should take
less than an hour for an intermediate PHP person to get to hello world
(welcome_message.php). Time: 1 hour.
2) Once you've got CI running, put the latest copy of FX.php,
FX_Error.php, and FX_constants.php in CI's application/libraries/
directory. Time: 5 minutes tops.
....THIS STEP CHANGED from previous message....
3) Drop this class extension into the same directory with FX.php (CI's
application/libraries/ directory).
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*------------------------------------------------------------------*/
// DEC 20070413 wrapper for CI integration
// needs to be able to init with params in an array
// load these using config file FX.php
/*------------------------------------------------------------------*/
require('FX.php');
class CIFX extends FX {
function CIFX ($params)
{
parent::FX(
$params['dataServer'],
$params['dataPort'],
$params['dataType'],
$params['dataURLType']
);
}
}
?>
This class extension for FX.php lets CI load FX.php with an array as an
argument. External libraries like FX.php need no direct modifications to
integrate with CI properly - just extend them with a wrapper function
that accepts arrays and passes them on.
In summary, you need a new class called CIFX which will be the new
constructor. It translates the array passed in by the CI class loader
into the 4 parameters the normal FX.php constructor can understand.
Time: Another 5 minutes, tops.
....THIS STEP CHANGED from previous message...
4) Make a file called CIFX.php (the same name as the class so CI can
load it automatically) and put it in CI's application/config/ directory.
It should contain the data that is normally found in server_data.php in
the FX.php distribution but formatted like a PHP file like this:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| FX FMP database access data
|--------------------------------------------------------------------------
*/
$config['dataServer']='127.0.0.1';
$config['dataPort']='591';
$config['dataType']='FMPro5/6'; // or FMPro7
$config['dataURLType']='http';
?>
CI will load this data and pass it to the new CIFX.php class constructor
for you - it can do that because the names are the same. Time: 5 more
minutes.
....THIS STEP CHANGED from previous message...
5) Almost there... make a "controller" file called "search.php" and put
it in the application/controllers/ directory with this PHP code (modify
the database, layout and field data):
<?php
class Search extends Controller {
function Search()
{
parent::Controller();
}
function id($id)
{
// CI knows where to find the
// CIFX.php FX wrapper file at
// CI path: application/libraries/CIFX.php
// FMP WPE data (IP, port, server version,
// and url scheme) is in custom config file at
// CI path: application/config/CIFX.php
$this->load->library('CIFX');
// tell FX which DB, layout to use and
// how many records to return
$this->cifx->SetDBData('database.fp5', 'layout', 1);
// build a find request, field name, data, comparison
$this->cifx->AddDBParam ('id', $id, 'eq');
// do find, return dataset, no flattening, meta object
$res = $this->cifx->DoFXAction(FX_ACTION_FIND, TRUE, TRUE);
echo '<pre>';
print_r($res);
echo '</pre>';
}
}
?>
This AddDBParam example assumes you have a database with the fieldname
'id' - you, of course, can change that to suit. I suggest just pointing
the FX requests to a database you've already got set up and working.
Time: If you use a database already set up, 5 minutes to modify this
code and fire it up.
6) Point your browser to:
http://example.com/path_to_CI/index.php/search/id/1
Note: if you followed the CI install instructions on how to use an
.htaccess file to use mod_rewrite for nice urls, then you can drop the
index.php and just use:
http://example.com/path_to_CI/search/id/1
....THIS DESCRIPTION CHANGED from previous message...
CI takes the URL segments and loads one as a controller file (search),
calls one as a function (id), and passes the last one as a variable (1)
for your id() controller function to use as a search parameter. Nice and
sweet. It's a great way of organizing projects!
Let me know if you have problems with this. I'd like to get a little
feedback from the FX folks first and then post instructions at the CI
forums.
Did it take you an hour and 20 minutes? Let me know!
dan
More information about the FX.php_List
mailing list