 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
MikeD
Joined: 15 Jan 2008 Posts: 4
|
Posted: Tue Jan 15, 2008 4:00 am Post subject: XML render problem |
|
|
Need to create an XML output that looks like this:
| Code: |
<data>
<entry>
<id>0</id>
<username>User1</username>
<fileLocation>images/01.jpg</fileLocation>
<isFriend>0</isFriend>
<link>
<title>User1 Link1</title>
<url>http://www.google.com</url>
</link>
<link>
<title>User1 Link2</title>
<url>http://www.google.com</url>
</link>
</entry>
<entry>
<id>1</id>
<username>User2</username>
<fileLocation>images/02.jpg</fileLocation>
<isFriend>0</isFriend>
<link>
<title>User2 Link1</title>
<url>http://www.google.com</url>
</link>
<link>
<title>User2 Link2</title>
<url>http://www.google.com</url>
</link>
</entry>
</data> |
I've got the dbdo factory pulling my data and I build an array to pass to bind, and if I disregard trying to build the link area above I've got everything outputting just peachy.
| Code: | $user_grid = DB_DataObject::factory( 'users' );
$user_grid->selectAdd();
$user_grid->selectAdd('id, username');
$user_grid->find();
// build array to hold the output
$ouptut = array();
while ($user_grid->fetch()) {
// output array
$output[] = array(
'id' => $user_grid->id,
'username' => $user_grid->username,
'fileLocation' => '/file/system/path/to/the/faceshot/image.jpg',
'isFriend' => 0,
);
}
// hook it all up
$rendererOptions = array(
'fieldAttribute' => null,
'outerTag' => 'data',
'rowTag' => 'entry',
'useXMLDecl' => false
);
$datagrid =& new Structures_DataGrid();
$test = $datagrid->bind($output);
$test = $datagrid->render(DATAGRID_RENDER_XML, $rendererOptions); |
so when I run that I get:
| Code: |
<data>
<entry>
<id>23</id>
<username>mike dee</username>
<fileLocation>/file/system/path/to/the/faceshot/image.jpg</fileLocation>
<isFriend>0</isFriend>
</entry>
<entry>
<id>24</id>
<username>nick123</username>
<fileLocation>/file/system/path/to/the/faceshot/image.jpg</fileLocation>
<isFriend>0</isFriend>
</entry>
</data>
|
and all is as it should be.
But -- I need to get those link nodes in with their child data nodes - if I try to nest another array into $output[] as:
| Code: |
'link' => array('title'=>'User1 Link1', 'url' => 'http://www.google.com');
|
I get an error that indicates that xml_util wants a string.
How do I best add these child nodes? XML render really needs some usage examples |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1051
|
Posted: Tue Jan 15, 2008 10:36 am Post subject: |
|
|
That's not directly supported by SDG, and we won't add support for this special case -- if we would do it for one special case, we would have to do it for every special case.
But: You can overload the XML renderer to add these additional tags to the output. The method that you need to overload is buildRow(). If you need more details, don't hesitate to ask. |
|
| Back to top |
|
 |
MikeD
Joined: 15 Jan 2008 Posts: 4
|
Posted: Tue Jan 15, 2008 4:39 pm Post subject: |
|
|
Morning Mark
| mark wrote: | | That's not directly supported by SDG, and we won't add support for this special case -- if we would do it for one special case, we would have to do it for every special case. |
I'm not sure I understand - you're saying that Structures_DataGrid_Renderer_XML isn't an SDG component when it comes to supporting SDG??
| Quote: | | But: You can overload the XML renderer to add these additional tags to the output. The method that you need to overload is buildRow(). If you need more details, don't hesitate to ask. |
Yes, I could use some additional detail, do you have an example or something you could post? I was considering looking into addcolumn() as well. |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1051
|
Posted: Tue Jan 15, 2008 4:56 pm Post subject: |
|
|
| MikeD wrote: | | I'm not sure I understand - you're saying that Structures_DataGrid_Renderer_XML isn't an SDG component when it comes to supporting SDG?? |
It is a component of SDG, yes. What I meant: We won't add support for your additional tags in the XML renderer of SDG. Too many people would then request more and more special cases, and the renderer's code would grow and grow.
| MikeD wrote: | | Yes, I could use some additional detail, do you have an example or something you could post? |
You would make your own renderer class, e.g. like this:
| Code: |
class Structures_DataGrid_Renderer_MikeXML
extends Structures_DataGrid_Renderer_XML
{
function buildRow($index, $data)
{ ... }
}
|
This class could be used by calling e.g. $datagrid->render('MikeXML'); (the other SDG methods for choosing the renderer can also be used, of course).
Instead of the three dots you can place the original contents of the buildRow method from the XML renderer. After the foreach loop you can add your own custom tags to the $xml string. |
|
| Back to top |
|
 |
|
|
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
|
|