Re: Binding Structures_DataGrid and DB_DataObject
| From: | Barry Steele | Date: | Tue, 04 Oct 2005 12:16:08 +0000 |
| Subject: | Re: Binding Structures_DataGrid and DB_DataObject | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-21224@lists.php.net to get a copy of this message | ||
Hi
Thanks for the tutorial it provides a good outline on using DataGrids
where one needs to execure simple queries.
Has anyone considered the following example:
class DataObject_Employee extends DB_DataObject
{
var $__table = "employee";
var $id;
var $name;
var $dept; // FK = dept.id
var $gender;
var $something_else_important
.... etc
}
class DataObject_Dept extends DB_DataObject
{
var $__table = "dept";
var $id;
var $dept_name
var $location;
... etc
}
$folks = new DataObject_Employee();
$dept = new DataObject_Dept();
$dept_name = 'Surfing';
$dept->joinAdd($folks);
$sept->selectAdd();
$dept->selectAdd('dept_name','name');
$dept->orderBy('dept_name);
..
etc (BTW - code above meant as example only. )
When we tried something like this (we had about 5 tables I think - pretty
standard ), we found that the result lists not only the columns one would
expect ('dept_name','name') but also all of the other columns in table
'dept', albiet with null values.
I have not had time to try to fix this, but we have identified the issue
as inherent in DataObjects. If one does a var_dump($dept->toArray()) in
the fetch loop, the output includes all fields in dept table as well as
those in the selectAdd() call.
Has anyone else seen this and if so did you fix it or like us resott to
queries and DB ?
Barry Steele
On Mon, October 3, 2005 9:27 am, Olivier Guilyardi said:
> Dear PEAR users,
>
> I have written a new tutorial about Structures_DataGrid and DB_DataObject.
>
> It explains how to easily turn an SQL table into an HTML table with
> sorting and
> paging.
>
> TITLE: Database frontend with PEAR DataGrid and DataObject
> URL: http://www.samalyse.com/code/pear/dgdo
>
> I have been submitting it for review on the pear-dev list, and since I got
> some
> good feedback, I decided to post it in here.
>
> Enjoy,
>
> --
> og
>
--
Stay happy, stay well ... get involved
Barry Steele
www.hpfm.com.au
mob: +61 413 947980
off: +61 2 99816329
fax: +61 2 9981 7806