Extending classes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jez

    #1

    Extending classes

    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($dbho st,$dbname,$dbu ser,$dbpass,$sq l);
    $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($dbho st,$dbname,$dbu ser,$dbpass,$sq l);
    $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
Working...