php) to which you append the query string you just built:
$amazon_url = AMAZON_REST_BASE_URL . $query_string;
Using the file_get_contents() function, you make a simple HTTP GET request to Amazon. It??™s just like typing
the address in your browser:
// Get the XML response using REST
$amazon_xml = file_get_contents($amazon_url);
The $amazon_xml variable will contain a string with the returned XML data. To further process it, we use the
simplexml_load_string() function that parses the XML text and returns a SimpleXMLElement object representing
the XML document. Read more details at http://www.php.net/manual/en/function.simplexmlload-
string.php.
// Unserialize the XML and return
return simplexml_load_string($amazon_xml);
}
CHAPTER 22 ?– USING AMAZON.COM WEB SERVICES 681
The _GetDataWithSoap() method has similar functionality as _GetDataWithRest(), but it makes the
ItemSearch operation using SOAP. The logic this method uses to contact AWS is the same as in the page you
wrote earlier in this chapter.
Implementing the Presentation Tier
Let??™s create the componentized template that will display the t-shirts and then modify the
departments_list componentized template to include this new department.
Exercise: Displaying Amazon.com Products in TShirtShop
1. Add a new file named amazon_products_list.tpl in the presentation/templates folder of your
project, and add the following code in it:
{* amazon_products_list.
Pages:
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796