PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Array DataSource

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Structures
View previous topic :: View next topic  
Author Message
Mungbeans



Joined: 10 Jan 2007
Posts: 30
Location: Sydney, Australia

PostPosted: Mon Feb 19, 2007 11:11 am    Post subject: Array DataSource Reply with quote

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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Mon Feb 19, 2007 1:53 pm    Post subject: Reply with quote

$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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Mon Feb 19, 2007 1:56 pm    Post subject: Reply with quote

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
View user's profile Send private message
Mungbeans



Joined: 10 Jan 2007
Posts: 30
Location: Sydney, Australia

PostPosted: Tue Feb 20, 2007 1:46 am    Post subject: Reply with quote

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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Tue Feb 20, 2007 12:05 pm    Post subject: Reply with quote

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
View user's profile Send private message
Mungbeans



Joined: 10 Jan 2007
Posts: 30
Location: Sydney, Australia

PostPosted: Thu Feb 22, 2007 2:58 am    Post subject: Reply with quote

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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Thu Feb 22, 2007 11:20 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Structures All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software