


<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Fresh Click Media &#187; PHP</title>
	<atom:link href="http://www.freshclickmedia.com/blog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.freshclickmedia.com</link>
	<description></description>
	<lastBuildDate>Mon, 08 Mar 2010 07:51:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Professional CodeIgniter Book Review</title>
		<link>http://www.freshclickmedia.com/blog/2008/12/professional-codeigniter-book-review/</link>
		<comments>http://www.freshclickmedia.com/blog/2008/12/professional-codeigniter-book-review/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 18:06:10 +0000</pubDate>
		<dc:creator>Shane</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.freshclickmedia.com/?p=119</guid>
		<description><![CDATA[<img src="http://www.freshclickmedia.com/wp-content/uploads/2008/12/codeigniterbook.jpg" alt="" title="CodeIgniter Book Review" width="590" height="100" />

With all the furore surrounding Ruby on Rails, you'd be forgiven for forgetting that any other web application framework ever existed.  The fact is, of course, that there are many to choose from, and one leading PHP-based framework is MVC-based CodeIgniter.

The <a href="http://codeigniter.com/">CodeIgniter</a> website is a great place to start for newcomers and more experienced developers alike, but I still like a good book, that I can hold in my hand and digest.  Wrox's <a href="http://www.wrox.com/WileyCDA/WroxTitle/Professional-CodeIgniter.productCd-0470282452.html">Professional CodeIgniter</a> is such a book, and presents a good overview of the framework that's getting deserved attention in the web development community.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.freshclickmedia.com/wp-content/uploads/2008/12/codeigniterbook.jpg" alt="" title="CodeIgniter Book Review" width="590" height="100" /></p>
<p>With all the furore surrounding Ruby on Rails, you&#8217;d be forgiven for forgetting that any other web application framework ever existed.  The fact is, of course, that there are many to choose from, and one leading PHP-based framework is MVC-based CodeIgniter.</p>
<p>The <a href="http://codeigniter.com/">CodeIgniter</a> website is a great place to start for newcomers and more experienced developers alike, but I still like a good book, that I can hold in my hand and digest.  Wrox&#8217;s <a href="http://www.wrox.com/WileyCDA/WroxTitle/Professional-CodeIgniter.productCd-0470282452.html">Professional CodeIgniter</a> is such a book, and presents a good overview of the framework that&#8217;s getting deserved attention in the web development community.</p>
<p>The book weighs in at a fairly lightweight 336 pages, but covers various aspects of CodeIgniter development, together with a history of the <a href="http://en.wikipedia.org/wiki/Model_View_Controller">Model View Controller Pattern</a> and an examination of <a href="http://en.wikipedia.org/wiki/Agile_software_development">Agile Development</a> that is often employed by modern web-centric development teams.  Whilst these discussions are not completely necessary to experienced programmers looking at getting to grips with CodeIgniter, they may benefit others who are looking for a more rounded introduction to web development.  Being familiar with MVC and agile-development, I skipped these sections and headed for some CodeIgniter code.</p>
<p>Chapter 3 satisfies my code craving, where an overview of CodeIgniter is presented, covering such topics as the default installation, configuration, CodeIgniter libraries, helpers, and models, views and controllers, the foundation of any CodeIgniter site.</p>
<p>Chapters 4-8 walks through the development of an e-commerce style website with a shopping cart, categories and products, and a dashboard for managing details of the site.  Chapter 9 covers some security issues, and although the information is presented, it is not intended as an exhaustive coverage  of PHP Security.  There is never a one book fits all situation, and for PHP security, you&#8217;re likely to find <a href="http://phpsecurity.org/">Essential PHP Security</a> of great use.</p>
<p>The book concludes with an brief examination of the site launch, though this adds little of any significant importance.</p>
<p>It&#8217;s good to see a CodeIgniter book, and the quality of the writing is generally high, with easy to follow code examples.  The book is very thin on AJAX coverage, which is quite a negative.  Used in conjunction with the excellent <a href="http://codeigniter.com/forums/">CodeIgniter forums</a> and website, it&#8217;s likely to prove a great resource for learning the framework.</p>
<p>The book&#8217;s list of Chapters is as follows:</p>
<ol>
<li>Welcome to the MVC World</li>
<li>Agile Methodologies and Approaches</li>
<li>A 10,000-Foot View of CodeIgniter</li>
<li>Creating the Main Website</li>
<li>Building a Shopping Cart</li>
<li>Creating a Dashboard</li>
<li>Improving the Dashboard</li>
<li>Last-minute Upgrades</li>
<li>Security and Performance</li>
<li>Launch</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.freshclickmedia.com/blog/2008/12/professional-codeigniter-book-review/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Displaying Amazon lists on your blog using PHP</title>
		<link>http://www.freshclickmedia.com/blog/2007/11/displaying-amazon-lists-on-your-blog-using-php/</link>
		<comments>http://www.freshclickmedia.com/blog/2007/11/displaying-amazon-lists-on-your-blog-using-php/#comments</comments>
		<pubDate>Mon, 26 Nov 2007 13:18:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.freshclickmedia.com/blog/2007/11/displaying-amazon-lists-on-your-blog-using-php/</guid>
		<description><![CDATA[A common feature of blogs is the listing of albums or books that the author is currently enjoying.  This article explains how to set up such a list in Amazon and show it on your blog using PHP and a REST web service.

If you&#8217;ve visited Amazon, you&#8217;ll have noticed that every time you view [...]]]></description>
			<content:encoded><![CDATA[<p>A common feature of blogs is the listing of albums or books that the author is currently enjoying.  This article explains how to set up such a list in Amazon and show it on your blog using PHP and a REST web service.<br />
<span id="more-71"></span></p>
<p>If you&#8217;ve visited Amazon, you&#8217;ll have noticed that every time you view an item, it will be accompanied by a number of Lists, or &#8216;Listmania&#8217; items.  Each Listmania list has a title and a list of between 1 and 25 Amazon items.</p>
<p>A listmania that I&#8217;ve created can be <a href="http://www.amazon.co.uk/Currently-listening-to/lm/R2LGMJ3BF2KY9B/ref=cm_lm_byauthor_title_full">found here</a>.  As you can see, I&#8217;m quite a fan of Pink Floyd, but you can obviously put whatever you want in your own list.</p>
<p>To create your list, visit the &#8216;Your Store&#8217; tab and login.  Once you&#8217;re in, click on the &#8216;YOUR PROFILE&#8217; link that appears below the &#8216;Your store&#8217; tab (which has now changed to include your name.)  </p>
<p><img src="http://farm3.static.flickr.com/2091/2065946658_4776ecaef2_o.png" alt="Clicking on the profile link" /></p>
<p>Once the page has loaded, scroll down to the Listmania! section, and click on the &#8220;Create a Listmania!&#8221; List link.</p>
<p><img src="http://farm3.static.flickr.com/2116/2065946672_4c575c71d7_o.png" alt="Creating a listmania list" /></p>
<p>Once the page loads, you will be presented with the opportunity to create your list.  Provide a name, your qualifications (I don&#8217;t know why this is relevant), and a list of ISBN/ASINs, which uniquely identify the product (there&#8217;s more information about these on the page.)</p>
<p><img src="http://farm3.static.flickr.com/2419/2065149395_5df48ca24e_o.png" alt="Setting up the list" /></p>
<p>Once the list is set up, we&#8217;ll need to make a request to an Amazon web service to get the information to display on the site.  The first thing to do is head over to the <a href="http://www.amazon.com/gp/aws/landing.html">Amazon Web Services site</a> and sign up a free Amazon web services account.  Amazon requires that you do this because you&#8217;ll need a &#8216;developer token&#8217; before you can request any information.  </p>
<p>There&#8217;s a huge amount of documentation available on the <a href="http://www.amazon.com/gp/aws/landing.html">Amazon Web Services site</a>, but we&#8217;ll be focussing on calling the web service using <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST</a>.  This basically means that we&#8217;ll be making a web request to a specific URI, and getting back some XML, which we&#8217;ll parse and display on the site.</p>
<p>There a large number of web services, but our particular area of interest for retrieving our Listmania information is the <a href="http://docs.amazonwebservices.com/AWSEcommerceService/2007-01-17/">Amazon E-Commerce Service</a>.  We&#8217;ll be using the <a href="http://docs.amazonwebservices.com/AWSEcommerceService/2007-01-17/ApiReference/ListLookupOperation.html">&#8216;ListLookupOperation&#8217;</a> to get our Listmania information.  The excellent documentation specifies a number of parameters, and our URL will look something like this:</p>
<pre class="code">http://webservices.amazon.co.uk/onca/xml?Service=AWSECommerceService&#038;AWSAccessKeyId=&lt;Access Key&gt;&#038;Operation=ListLookup&#038;ListType=Listmania&#038;ListId=&lt;List ID&gt;&#038;ResponseGroup=ListFull,Images</pre>
<p>The Operation parameter is set to &#8216;ListLookup&#8217; and the ListType to &#8216;Listmania&#8217;.  The ResponseGroup determines what information our XML response will contain; in this instance, we&#8217;ll get full list information with image data.  The AWSAccessKeyId is the ID you received when you signed up for the web services access, and the ListId is the ID of your listmania list (R2LGMJ3BF2KY9B for the one I described earlier.)</p>
<p>Quite a lot of XML&#8217;s returned, but a fragment is shown below:</p>
<pre class="code">
&lt;List&gt;
	&lt;ListId&gt;R2LGMJ3BF2KY9B&lt;/ListId&gt;
	&lt;ListURL&gt;http://www.amazon.co.uk/gp/richpub/listmania/fullview/R2LGMJ3BF2KY9B&lt;/ListURL&gt;
	&lt;ListName&gt;Currently listening to&lt;/ListName&gt;
	&lt;ListType&gt;Listmania&lt;/ListType&gt;
	&lt;TotalItems&gt;9&lt;/TotalItems&gt;
	&lt;TotalPages&gt;1&lt;/TotalPages&gt;
	&lt;DateCreated&gt;2007-06-08&lt;/DateCreated&gt;
	&lt;ListItem&gt;
		&lt;ListItemId&gt;RI3KA9OMXBJK39M&lt;/ListItemId&gt;
		&lt;Comment&gt;Final cut&lt;/Comment&gt;
		&lt;Item&gt;
			&lt;ASIN&gt;B0001KZM3O&lt;/ASIN&gt;
			&lt;SmallImage&gt;
				&lt;URL&gt;http://ecx.images-amazon.com/images/I/1163ZHTF2RL.jpg&lt;/URL&gt;
				&lt;Height Units="pixels"&gt;75&lt;/Height&gt;
				&lt;Width Units="pixels"&gt;75&lt;/Width&gt;
			&lt;/SmallImage&gt;
			&lt;MediumImage&gt;
				&lt;URL&gt;http://ecx.images-amazon.com/images/I/21QXBZ2M09L.jpg&lt;/URL&gt;
				&lt;Height Units="pixels"&gt;160&lt;/Height&gt;
				&lt;Width Units="pixels"&gt;160&lt;/Width&gt;
			&lt;/MediumImage&gt;
			&lt;LargeImage&gt;
			&lt;URL&gt;http://ecx.images-amazon.com/images/I/510WJ1ASB3L.jpg&lt;/URL&gt;
				&lt;Height Units="pixels"&gt;455&lt;/Height&gt;
				&lt;Width Units="pixels"&gt;455&lt;/Width&gt;
			&lt;/LargeImage&gt;
			&lt;!-- more information removed for brevity --&gt;
			&lt;ItemAttributes&gt;
				&lt;Title&gt;The Final Cut: Remastered&lt;/Title&gt;
			&lt;/ItemAttributes&gt;
		&lt;/Item&gt;
	&lt;/ListItem&gt;
&lt;/List&gt;
</pre>
<h3>Making the request for the XML using PHP</h3>
<p>To request the XML, we&#8217;ll use <a href="http://uk2.php.net/curl">CURL</a>, the Client URL Library, available since PHP version 4.0.2.  For our needs, the code is quite simple:</p>
<pre class="code">
$key = "YOURACCESSKEY";
$listID = "R2LGMJ3BF2KY9B";

$url = "http://webservices.amazon.co.uk/onca/xml?Service=AWSECommerceService&#038;AWSAccessKeyId=" . $key . "&#038;Operation=ListLookup&#038;ListType=Listmania&#038;ListId=" . $listID . "&#038;ResponseGroup=ListFull,Images";    	

// make request to amazon:
$c = curl_init( $url);
curl_setopt( $c, CURLOPT_RETURNTRANSFER, 1);
$xmlResponse = curl_exec( $c);
curl_close( $c);
</pre>
<p>Initially, we define two variables to store our access key and the id of the list we want to access.  The next line creates the URL for the REST web service, building up the various parts to include the access key and list id.</p>
<p>We use CURL in the initial call to curl_init, passing in the URL for the web service.  The next line, where we call curl_setopt, is important, since it determines that the response from the URL in the curl_exec line will be assigned to a string, rather than being output directly.  This is important, since we&#8217;re going to be parsing it.  curl_exec will get the response and the final line, calling curl_close, closes the CURL session and frees the associated resources.</p>
<h3>Parsing the XML</h3>
<p>To parse the XML, we&#8217;ll use <a href="http://uk3.php.net/simplexml">SimpleXML</a>, which requires PHP5.  Using Simple XML simplifies XML handling, and fits all our needs for this example.</p>
<p>The obvious questions when parsing some XML are what are the elements that we&#8217;ll be parsing, and what are we going to output to the response.  Well, looking at the XML fragment shown above gives us some clues as for the XML structure, and for the response, I&#8217;ve decided to go for a definition list containing an album image and the album name.  For CSS styling, I&#8217;ll give the definition list a class of &#8220;listmania&#8221;.  With all this in mind, we get the following PHP code:</p>
<pre class="code">
$xml = simplexml_load_string( $xmlResponse);

$listManiaHtml = "&lt;dl class=\"listmania\"&gt;";

$itemCount = 0;

foreach( $xml-&gt;Lists-&gt;List-&gt;ListItem as $listItem)
{

		$listManiaHtml .= "&lt;dt&gt;";
		$listManiaHtml .= $listItem-&gt;Item-&gt;ItemAttributes-&gt;Title;
		$listManiaHtml .= "&lt;/dt&gt;";
		$listManiaHtml .= "&lt;dd&gt;";
		$listManiaHtml .=  "&lt;a href=\"http://www.amazon.co.uk/gp/product/" . $listItem-&gt;Item-&gt;ASIN . "\" title=\"" . $listItem-&gt;Item-&gt;ItemAttributes-&gt;Title . "\"&gt;";
		$listManiaHtml .= "&lt;img src=\"" . $listItem-&gt;Item-&gt;SmallImage-&gt;URL . "\" alt=\"" . $listItem-&gt;Item-&gt;ItemAttributes-&gt;Title . "\" /&gt;";
		$listManiaHtml .= "&lt;/a&gt;";
		$listManiaHtml .= "&lt;/dd&gt;";
}

$listManiaHtml .= "&lt;/dl&gt;";
</pre>
<p>To begin, the XML response from the REST web service is loaded using simple_xml_load_string function.  I define a variable to store the listmania output, and begin by assigning the opening tag of the definition list.</p>
<p>Using simple XML&#8217;s traversal methods, I can associate XML elements in the response directly using a chained -> syntax.  Each album is enclosed in a ListItem element, and this is referenced in the foreach loop.  Within this loop, the ListItem element&#8217;s Title, ASIN (Amazon identifier), and small image URL are extracted and appended to the listmania output variable.  The ASIN is used in a hyperlink to link directly to the album on the Amazon website.</p>
<p>Doing a simple echo on the resulting listmania variable is all that&#8217;s then required to output the semantic listmania.  Shown below is what the output looks like:</p>
<pre class="code">
&lt;dl class="listmania"&gt;
    &lt;dt&gt;The Final Cut: Remastered&lt;/dt&gt;
    &lt;dd&gt;
        &lt;a href="http://www.amazon.co.uk/gp/product/B0001KZM3O" title="The Final Cut: Remastered"&gt;
            &lt;img src="http://ecx.images-amazon.com/images/I/1163ZHTF2RL.jpg" alt="The Final Cut: Remastered" /&gt;
        &lt;/a&gt;
    &lt;/dd&gt;

    &lt;dt&gt;Libertad (Special Edn)&lt;/dt&gt;
    &lt;dd&gt;
        &lt;a href="http://www.amazon.co.uk/gp/product/B000QEIMJG" title="Libertad (Special Edn)"&gt;
            &lt;img src="http://ecx.images-amazon.com/images/I/11LmOg0O4pL.jpg" alt="Libertad (Special Edn)" /&gt;
        &lt;/a&gt;
    &lt;/dd&gt;
&lt;/dl&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.freshclickmedia.com/blog/2007/11/displaying-amazon-lists-on-your-blog-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
