Passing PHP Variables from CMS Builder to XML

9 posts by 2 authors in: Forums > CMS Builder
Last Post: November 19, 2010   (RSS)

By Rusty - November 18, 2010 - edited: November 18, 2010

I'm trying to pass PHP variables from CMS Builder to an XML file. This XML file is called up by a Flash image slider.

I want to be able to enter data into CMS Builder and have it stored as a variable.
I want to then call up the PHP variable and pass it into the XML file.
The XML file is then called by the Flash SWF file and renders the data in the Flash object.

I can't seem to find a good way to do this. Anyone have any suggestions? I know it should be possible.

I've been referencing the walk-through here: http://www.interactivetools.com/docs/cmsbuilder/slideshowpro.html

Here's a snippet of what I have, but I keep getting the Flash object, but w/o the data I want.

<?php header('Content-type: application/xml; charset=utf-8'); ?><?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<?php

require_once "/public_html/admin/lib/viewer_functions.php";

list($f00Records, $f00MetaData) = getRecords(array(
'tableName' => 'f00',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$f00 = @$f00Records[0]; // get first record

// show error message if no matching record is found
if (!$f00Record) {
header("HTTP/1.0 404 Not Found");
print "f00 Record not found!";
exit;
}

?>
<portfolio>

<!-- info 1-->
<title><?php echo $f00Record['title'] ?></title>
<description><![CDATA[<?php echo $f00Record['description'] ?>
]]></description>
</portfolio>

Rusty

Re: [Rusty] Passing PHP Variables from CMS Builder to XML

By Jason - November 18, 2010

Hi Rusty,

Are you getting any errors? If you put the name of the xml file in your address bar what is displayed? How is it different from what you're expecting?

Let me know and if you can provide a url to your file I can take a look for you.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Passing PHP Variables from CMS Builder to XML

By Rusty - November 18, 2010 - edited: November 18, 2010

Yeah I actually checked that and figured out I was getting an error about 15 minutes ago and have been digging on that.

I get this error when I try to simply render the slider.xml.php


XML Parsing Error: syntax error
Location: slider.xml.php
Line Number 2, Column 1:Warning: session_start(): Cannot send session cache limiter - headers already sent (output
started at /public_html/slider.xml.php:1) in /public_html/admin/lib/init.php on line 309
^

Rusty

Re: [Rusty] Passing PHP Variables from CMS Builder to XML

By Jason - November 18, 2010

Hi Rusty,

Check to make sure there is nothing between the top of the line and your first line. This error is sometimes caused by a blank line at the top of the page.

If that doesn't work, please attach your slider.xml.php file to this thread so I can take a closer look.

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Rusty] Passing PHP Variables from CMS Builder to XML

By Rusty - November 18, 2010 - edited: November 18, 2010

Made some headway...

Based off of the premise that the headers will be sent by ANYTHING that comes after the doctype, I switched it around to declare the doctype AFTER I call the data from the table:

So now the beginning of my XML file looks like this:

<?php
require_once "/public_html/admin/lib/viewer_functions.php";
list($f00Records, $f00MetaData) = getRecords(array(
'tableName' => 'f00',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$f00rRecord = @f00Records[0]; // get first record
// show error message if no matching record is found
if (!$f00rRecord) {
header("HTTP/1.0 404 Not Found");
print "f00 Record not found!";
exit;
}
?><?php header('Content-type: application/xml; charset=utf-8'); ?><?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>


But I am also getting another error that I believe resolves from trying to use the plaintext & instead of the html number.

More or less, the commonly used & (ampersand) is one of a handful of special characters which cause an XML string to error out when it tries to parse the data. Others that it happens to screw up/error out with are (#, <, >, &).

I'm currently going to try wrapping this around my plaintext. I was trying to list plaintext like "Item A & Item B" and it is erroring out on the &.

This is what I wrapped around my PHP vars.
<!-- info 1-->
<title><![CDATA[<?php echo $f00Record['title'] ?>]]></title>
<description><![CDATA[<?php echo $f00Record['description'] ?>]]></description>

Rusty

Re: [Rusty] Passing PHP Variables from CMS Builder to XML

By Jason - November 19, 2010

Hi Rusty,

I would recommend filling out a [url http://www.interactivetools.com/support/]2nd Level Support Request[/url] and we can take a closer look into this issue.

Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Passing PHP Variables from CMS Builder to XML

By Rusty - November 19, 2010 - edited: November 19, 2010

Jason, Thanks but I actually was able to work through the issue I was having myself.

The resulting source code that worked for me can be referenced in Post # 6 http://www.interactivetools.com/forum/gforum.cgi?post=84693#84693.

The changing/fixing factor was twofold.

1) Make sure to call all the tables, etc, and have all the PHP code PRIOR to using echo to declare the document type as an XML file.
2) Wrapping my PHP variables (from CMS Builder) within the following Tag:
<!-- info 1-->
<title><![CDATA[<?php echo $f00Record['title'] ?>]]></title>
<description><![CDATA[<?php echo $f00Record['description'] ?>]]></description>


So with those two changes I was able to create a file that behaves as an XML file, but in reality contains PHP code. This enables a Flash SWF file to call up the PHP file (which behaves as an XML file), and the XML file calls upon the data references in the Database table (which was created by CMS builder).

I was also able to pass the PHP code to dynamically retrieve an URL Path, from an upload created within CMS builder to a Flash File, using the following bit of code:

<largeImage><![CDATA[<?php foreach ($f00Record['cycle_1_upload'] as $upload): ?>
<?php if ($upload['isImage']): ?><?php echo $upload['urlPath'] ?><?php endif?><?php endforeach?>]]>
</largeImage>



In a nutshell, figured it out on my own & got it working. The above code works great for me.
Rusty

Re: [Rusty] Passing PHP Variables from CMS Builder to XML

By Jason - November 19, 2010

Awesome. Glad to hear it's all working now.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/