470,833 Members | 1,410 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

Extending classes

Jez
I've created a database export class with extensions for exporting to
csv, xls, html and xml. The file export.inc.php contains the 'export'
class which deals with getting the data and storing the field names
and row data in arrays - used for all exports. export_csv.inc.php
include()s export.inc.php and contains 'export_csv' which extends the
export class, formatting the field name and row arrays as a csv file
and sending the file to the browser. There are other similar
extensions for xls, html and xml.

At the moment I have to do something like this to get my exported
data:

switch ($type) {
case "csv":
include("path/to/export_csv.inc.php");
$export = new export_csv();
break;
case "xls":
include("path/to/export_xls.inc.php");
$export = new export_xls();
break;
...
}

$export->get_data($dbhost,$dbname,$dbuser,$dbpass,$sql);
$export->output();

That seems quite untidy and what I'd really like to do is this:

include("path/to/export.inc.php");
$export = new export("csv");
$export->get_data($dbhost,$dbname,$dbuser,$dbpass,$sql);
$export->output();

I know it must be possible because that's how ADODB selects its
drivers, but I can't get my head round how it works. Any idea how I
should go about organising my classes and their separate files? Has it
got something to do with the 'factory method' that I've seen mentioned
in a few places recently?

Hope that makes sense?

Thanks!

Jez
Jul 17 '05 #1
0 1389

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Matt | last post: by
5 posts views Thread by needin4mation | last post: by
1 post views Thread by Sarge | last post: by
9 posts views Thread by Fat Elvis | last post: by
21 posts views Thread by Daz | last post: by
7 posts views Thread by Maximus Decimus | last post: by
5 posts views Thread by Wolfgang Hanke | last post: by
8 posts views Thread by Floortje | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.