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: [Jason] Passing PHP Variables from CMS Builder to XML

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

Opera gives me a slightly different error:
unexpected text (non-whitespace text outside root element)


XML parsing failed

XML parsing failed: syntax error (Line: 1, Character: 38)

1: <?xml version="1.0" encoding="UTF-8"?>
2: Warning: session_start(): Cannot send session cookie - headers already sent by (output started at/public_html/slider.xml.php:1) in /public_html/admin/lib/init.php on line 309
3:
4: 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
5: <portfolio>
6: <!-- info 1-->
7: <title>1 title</title>
8: <description><![CDATA[1 description ]]></description>


Based off of this it looks like my PHP is rendering fine. 1 title, & 1 description are the content that I have in the CMS, so that part is working properly.

It seems that the problem lies the the headers or cookies.

This is what the top portion of my XML file contains.
<?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',
));
$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;
}
?>


Internet Explorer provides this error
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Invalid at the top level of the document. Error processing resource '/slider.xml.php'. Line 1, Position 39

<?xml version="1.0" encoding="UTF-8"?>


######################

Edit

I went through and did some further research trying to figure out what was going on. Indeed yes, the session_start(): headers already sent Warning is generally a result of something causing the headers to be sent prematurely. This is commonly caused by blank lines or text before the session_start():.

So I went through and looked at my /admin/lib/viewer_functions.php & my /admin/lib/init.php & slider.xml.php files double & triple checking to make sure that there were no blank spaces, line breaks/returns or other crap there causing a premature delivery ;)

I find it interesting that the locations referenced are different for each browser:

FF:
Line Number 2, Column 1:

IE:
Line 1, Position 39

Opera:
Line: 1, Character: 38


Interestingly Enough...

According to my code,

Line: 1, Character: 38 is : the > in <?xml version="1.0" encoding="UTF-8"?>

And I have check and rechecked to remove ANY whitespaces at all. But the Opera error clues me in to the fact that it's Unexpected text (non-whitespace text

And I have no idea how that can be happening, or where it could be coming from.
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/