| View previous topic :: View next topic |
| Author |
Message |
Mungbeans
Joined: 10 Jan 2007 Posts: 30 Location: Sydney, Australia
|
Posted: Mon Feb 19, 2007 11:11 am Post subject: Array DataSource |
|
|
I've been googling and reading the tutorials to no avail. How do I get the array datasource to work?
Here is my code to date:
| Quote: | $arr = //associate array here
// Create the DataGrid, and bind the DataSource container
$datagrid =& new Structures_DataGrid();
$options = array();
$test = $datagrid->bind($arr, $options, DATAGRID_SOURCE_ARRAY);
if (PEAR::isError($test)) {
echo $test->getMessage();
}
|
My associate array is created using a third party database driver so I can't use the PEAR one, which leaves me trying to use the array datasource. |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Mon Feb 19, 2007 1:53 pm Post subject: |
|
|
$arr needs to be a 2-dimensional array:
$arr = array($row1, $row2, ...);
with $rowX = array($label1 => $col1, $label2 => $col2, ...);
(can be one big array of course, but I have splitted it to make it more readable)
$labelX is used as the column header of column X by default. |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Mon Feb 19, 2007 1:56 pm Post subject: |
|
|
| Another solution is the following: Take the MDB2 (or DBQuery) DataSource driver, copy it, and modify it. Using the concepts of one of these drivers is better than using the Array DataSource because they fetch only the records that need to be fetched (e.g. records 16-30 for page 2 when displaying 15 records per page). For large tables this might be even the only working solution. |
|
| Back to top |
|
 |
Mungbeans
Joined: 10 Jan 2007 Posts: 30 Location: Sydney, Australia
|
Posted: Tue Feb 20, 2007 1:46 am Post subject: |
|
|
| Quote: | $arr needs to be a 2-dimensional array:
$arr = array($row1, $row2, ...);
with $rowX = array($label1 => $col1, $label2 => $col2, ...); |
This is the actual format of my array. Was the code above correct? |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Tue Feb 20, 2007 12:05 pm Post subject: |
|
|
| Mungbeans wrote: | | Quote: | $arr needs to be a 2-dimensional array:
$arr = array($row1, $row2, ...);
with $rowX = array($label1 => $col1, $label2 => $col2, ...); |
This is the actual format of my array. Was the code above correct? |
It should be, yes.
Can you show the (shortened) output of var_dump($arr); here? Or send it to me via PM oder email?
What error messages do you get? |
|
| Back to top |
|
 |
Mungbeans
Joined: 10 Jan 2007 Posts: 30 Location: Sydney, Australia
|
Posted: Thu Feb 22, 2007 2:58 am Post subject: |
|
|
The error message said I hadn't supplied the correct datasource, but that was misleading. I traced through the code and realised the problem was that I have a different directory structure than the standard PEAR install.
So I've had to modify the class so it can find the files it needs. I've set it so it has the 'default' directory structure which, but can be over-written by a function call, eg:
$datagrid->setDirectory('includes/etc');
On another note - is there an example or tutorial somewhere on using the smarty datagrid renderer? |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Thu Feb 22, 2007 11:20 am Post subject: |
|
|
| Mungbeans wrote: | The error message said I hadn't supplied the correct datasource, but that was misleading. I traced through the code and realised the problem was that I have a different directory structure than the standard PEAR install.
So I've had to modify the class so it can find the files it needs. I've set it so it has the 'default' directory structure which, but can be over-written by a function call, eg:
$datagrid->setDirectory('includes/etc'); |
That's not a good idea. With the next update your changes will be overwritten.
The simple solution is: Use the PEAR installer and set your include_path to the right directory. With this, there is no need to change any PEAR source file.
| Mungbeans wrote: | | On another note - is there an example or tutorial somewhere on using the smarty datagrid renderer? |
An example can be found in the manual. |
|
| Back to top |
|
 |
|