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 
How to use XML renderer driver

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



Joined: 14 Aug 2007
Posts: 19
Location: Canada

PostPosted: Tue Oct 30, 2007 7:13 pm    Post subject: How to use XML renderer driver Reply with quote

Greeting. Couldn't quite figure out how to make use of the XML renderer driver with DataGrid. Any code snippet like what's in XLS.php header would be greatly helpful.

I am trying to convert MySql data in DataGrid to a XML file. Thanks everyone.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1002

PostPosted: Tue Oct 30, 2007 8:10 pm    Post subject: Reply with quote

Well, the basic usage is just this line:
Code:

$datagrid->render('XML');


Or, if you want to save it to a file:
Code:

$datagrid->render('XML', array('saveToFile' => true, 'filename' => 'example.xml'));


The tags that are used in the generated XML code can be customized via some options.

If you need more help on this topic, please ask more specific.
Back to top
View user's profile Send private message
Arnold



Joined: 14 Aug 2007
Posts: 19
Location: Canada

PostPosted: Tue Oct 30, 2007 8:56 pm    Post subject: Reply with quote

Wow. That's easy! I was thinking I need to instantiate a renderer object like in XLS or HTML table. Thanks for the quick response.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1002

PostPosted: Tue Oct 30, 2007 11:46 pm    Post subject: Reply with quote

Arnold wrote:
I was thinking I need to instantiate a renderer object like in XLS or HTML table.


Hmm, what are you doing with XLS and HTML? For not too difficult/special cases, these renders work quite similar to my XML example here.

If you want, show some snippets from your code here, if you're not sure about it. (Of course, if you want, using your own Spreadsheet_Excel_Writer or HTML_Table object together with $datagrid->fill() is also fine, but maybe you have something else in mind with your sentence from above.
Back to top
View user's profile Send private message
Arnold



Joined: 14 Aug 2007
Posts: 19
Location: Canada

PostPosted: Wed Oct 31, 2007 2:34 am    Post subject: Reply with quote

mark wrote:
Arnold wrote:
I was thinking I need to instantiate a renderer object like in XLS or HTML table.


Hmm, what are you doing with XLS and HTML? For not too difficult/special cases, these renders work quite similar to my XML example here.

If you want, show some snippets from your code here, if you're not sure about it. (Of course, if you want, using your own Spreadsheet_Excel_Writer or HTML_Table object together with $datagrid->fill() is also fine, but maybe you have something else in mind with your sentence from above.

I have been doing like what you said in the last paragraph. I create an instance of HTML_Table or Spreadsheet_Excel_Writer, set the options and call $datagrid->fill() and output the renderer data. Sample codes:
Code:

// Create the DataGrid, and bind the DataSource container
$datagrid = & new BarrelReportGrid($dataSource, $REPORT_MAX_BARRELS);

/*
 * generate Spreadsheet
 */
$xls =& new Spreadsheet_Excel_Writer(); // create an instance
$worksheet =& $xls->addWorksheet('inventory');
$columns=9;
$worksheet->setColumn(0, $columns, 15); // set width for first 9 columns

$titleFormat = & $xls->addFormat();
$titleFormat->setBold();
$titleFormat->setAlign('left');
$worksheet->write(0,0,"INVENTORY", $titleFormat);
$worksheet->write(1,0,"SQL Search Criteria: ".$_SESSION['sessFilter'], $titleFormat);

$colHeadingFormat =& $xls->addFormat();
$colHeadingFormat->setBold();
$colHeadingFormat->setAlign('center');
$colFormat = &$xls->addFormat();
$colFormat->setAlign('left');

$options = array('headerFormat' => &$colHeadingFormat,
                 'bodyFormat' => &$colFormat,
                 'startRow' => 4,
                 'worksheet' => &$worksheet);
$datagrid->fill($xls, $options);

$xls->send('inventory.xls'); // send HTTP headers to tell the browser what's coming
$xls->close();
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1002

PostPosted: Wed Oct 31, 2007 3:38 pm    Post subject: Reply with quote

Arnold wrote:
I have been doing like what you said in the last paragraph. I create an instance of HTML_Table or Spreadsheet_Excel_Writer, set the options and call $datagrid->fill() and output the renderer data. Sample codes: [...]


Okay, fine this way for such "complex" customizations. In the XML case, it's easier because there are not so many possibilities.

I have added an item on my TODO list about adding some more examples to the drivers.
Back to top
View user's profile Send private message
Arnold



Joined: 14 Aug 2007
Posts: 19
Location: Canada

PostPosted: Fri Nov 02, 2007 1:13 am    Post subject: Reply with quote

On a side note, XML renderer requires a newer version of DataGrid than I have so I updated to the latest 0.8.3 and all dependency libraries such as Pager. It appears to break all my pagers as I have been using renderer's getPaging() method. The header of renderer.php mentions that this function is now deprecated. But shouldn't it remain to work for old codes? Right now, it shows nothing. I have to change to the following method in order to get it working again.

Code:
$datagrid->getOutput(DATAGRID_RENDER_PAGER, $options);


Just want to make sure this is the expected behaviour for getPaging() method.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1002

PostPosted: Fri Nov 02, 2007 1:18 pm    Post subject: Reply with quote

The new code (with getOutput()) looks fine, although you might want to use simply the string 'Pager' instead of the constant.

You haven't posted your old code, but I guess that you have used something like $datagrid->renderer->...? There was a backwards compatibility break in release 0.7.0 (or 0.7.1). The changelog will tell you more.

Otherwise, please show the relevant lines from your old code that now don't work anymore.
Back to top
View user's profile Send private message
Arnold



Joined: 14 Aug 2007
Posts: 19
Location: Canada

PostPosted: Fri Nov 02, 2007 6:18 pm    Post subject: Reply with quote

Yes, I have been using Structure_DataGrid 0.7.1 for a while now. The codes that I have been using are as follow with the renderer object being a HTML_Table.
Code:

$renderer =& $datagrid->getRenderer();
/* Get and output HTML links */

$pagingHtml = $renderer->getPaging(array('separator'=>'', 'mode'=>'sliding',
                                         'prevImg'=>'<=', 'nextImg'=>'=>',
                                         'delta'=>'5'
                                   ));

echo "<p class='paging'>Pages : $pagingHtml</p>";

I have installed the latest packages to work with the latest Structures_DataGrid. Perhap I am missing to install a package or so:
Structures_DataGrid_Renderer_XML
Structures_DataGrid_Renderer_Pager
XML_Util
HTML_Table
HTML_Common
Pager
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1002

PostPosted: Fri Nov 02, 2007 7:02 pm    Post subject: Reply with quote

Instead of getPaging(), I recommend to use getOutput() or render():

$datagrid->render('Pager', array('pagerOptions' => array(...)));

'pagerOptions' is the same array that you passed to getPaging() before.

More details can be found here:
http://pear.php.net/manual/en/package.structures.structures-datagrid.structures-datagrid-renderer.pager.php
Back to top
View user's profile Send private message
Arnold



Joined: 14 Aug 2007
Posts: 19
Location: Canada

PostPosted: Fri Nov 02, 2007 9:45 pm    Post subject: Reply with quote

I have no problem to utilize the new method for new codes. I just wish it is backward compatible so I don't need to modify my existing codes. This can be tedious but not a big deal. Cheers.
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1002

PostPosted: Fri Nov 02, 2007 9:56 pm    Post subject: Reply with quote

BC compatibility is also PEAR's and our (= Structures_DataGrid developers) goal, but the 0.7 release got a major refactoring and clean-up, and it was reasonable to make the Pager usage according to other drivers. The old way wasn't really extensible in terms of adding new drivers (for which it makes sense to use paging, too). For future releases, BC are very unlikely.
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