Categories > TinyButStrong general >

converting to OOP

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: zenlord
Date: 2011-01-06
Time: 16:22

converting to OOP

Hi,

I have been using TBS for quite a while now, albeit probably not to 'clean' (it works, but I don't want to show you the code ;)).
Since I will be rewriting my website OOP-style, I have set my first steps in TBS with OOP, but I'm struggling (OOP itself and to apply it in TBS).

I got it to work after reading the manual and trying all sorts of stuff out. Is this the cleanest way to show a whole bunch of rows out of a db?
Class (relevant method only)
class Finance {
    function get_list_array($tbl) {
        $this->_res = @ pg_query($this->_conn, "SELECT * FROM $tbl ORDER BY date DESC");
        if (!$this->_res) {
            echo "Fetching result from tbl $tbl failed.\n";
            exit;
            }
        $this->_list = @ pg_fetch_all($this->_res);
        return ($this->_list);
        }
}

TBS code:
        $TBS = new clsTinyButStrong;
        $TBS->LoadTemplate("templates/bill_overzicht.htm");
            $TBS->MergeField("title_text","Overzicht van alle nota's");
            $TBS->MethodsAllowed = true;
            $F = new Finance;
            $TBS->ObjectRef["F"] = & $F;
            $TBS->MergeBlock("bill","array", $F->get_list_array("dossiers_bills"));
        pg_close(CNX_DOS);
        $TBS->Show();

Template:
                <tr>
                    <td>[bill.date;block=tr;frm='dd mmm yyyy']</td>
                    <td>[bill.user_id]</td>
                    <td>[bill.category]</td>
                    <td>[bill.amount;frm='€ 0,00']</td>
                    <td>[bill.status]</td>
                    <td>[bill.dos_nr]</td>
                </tr>

This works, but I tried to pass an object to TBS and all I got was a blank page, so I had to generate an array before passing it to TBS. If this is the way to go, than reading books about PHP on holiday have really paid off ;)
By: Skrol29
Date: 2011-01-06
Time: 16:54

Re: converting to OOP

Hi,

> This works, but I tried to pass an object to TBS and all I got was a blank page

Can you give a snippet of the code that does not work?
By: zenlord
Date: 2011-01-06
Time: 19:50

Re: converting to OOP

Well, I did read the manual again, and didn't know there was such a thing as an 'arrayobject-class' - which could explain my problems. I tried the example of the 'arrayObject' with a 'regular object'. I guess we can conclude that part of my question.

Is the above the correct way of listing more than 1 record, the TBS/OOP way?
By: Skrol29
Date: 2011-01-07
Time: 23:28

Re: converting to OOP

> Is the above the correct way of listing more than 1 record, the TBS/OOP way?

The template snippet is ok.

The PHP snippet has an superfluous line:
$TBS->ObjectRef["F"] = & $F;
This line is not needed because you merge the data as an array, not as an object data source.
By: zenlord
Date: 2011-01-08
Time: 11:41

Re: converting to OOP

Yes, that's probably a leftover from my tries to get an object to work - thx for pointing that out.