<?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>Antanova Ltd. &#187; php</title>
	<atom:link href="http://antanova.com/tags/php/feed" rel="self" type="application/rss+xml" />
	<link>http://antanova.com</link>
	<description>We make excellent websites</description>
	<lastBuildDate>Tue, 30 Mar 2010 09:08:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ASP.net style master pages in PHP</title>
		<link>http://antanova.com/blog/code-bits/asp-net-style-master-pages-in-php</link>
		<comments>http://antanova.com/blog/code-bits/asp-net-style-master-pages-in-php#comments</comments>
		<pubDate>Tue, 08 Dec 2009 17:16:02 +0000</pubDate>
		<dc:creator>Jason C</dc:creator>
				<category><![CDATA[Code-bits]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://antanova.com/?p=412</guid>
		<description><![CDATA[After seeing the lovely way that master pages work in ASP.net, I thought I'd try doing something similar in PHP.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not a .net developer. A few months ago, though, I was building a mini site for a property company, who&#8217;s hosting was on a .net server. I thought I&#8217;d have a go at using <a href="http://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx">master pages</a> instead of several different include files.</p>
<p>What a revelation! I really like the way that you specify a page that&#8217;s to be used as the template for the site, and simply add some place-holders that are to be populated with the content from your individual local pages. The whole thing then hangs together very nicely. You can even use relative links that are re-written by the server so no matter where you content page is, the link is always pointing at the same file. The code is clean, too, as the master and content pages are all marked up using XML, so all your code looks nice and is easy to follow in your editor of choice.</p>
<p>A different, but equally small site has now come up and it&#8217;s got me thinking about how to implement something like this in PHP. Now, there are several templating systems already out there for PHP, for example <a href="http://www.smarty.net">Smarty</a>. I didn&#8217;t want to use one of those, because like I said the site&#8217;s very small, and adding all those extra files in there and using the Smarty syntax would just unnecessarily increase the development time for such a small site. So, I set about making something up myself.</p>
<p>I&#8217;m pretty pleased with what I came up with: it&#8217;s not quite as clean as the .net version, but it is simple and easy enough that it will help rather than hinder the development of such as small site. I&#8217;ve got my template (the &#8216;master&#8217; page) on which I&#8217;ve defined a couple of areas where the content is to be dropped in.</p>
<p>template.php:</p>
<pre>&lt;?php Header("Content-Type: text/html; charset=UTF-8"); ?&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;&lt;?php echo $page-&gt;title; ?&gt;&lt;/title&gt;
    &lt;link rel="stylesheet" type="text/css" href="/path/to/stylesheet.css"&gt;
    &lt;?php echo $page-&gt;head; ?&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;nav&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;a href="/"&gt;Nav item 1&lt;/a&gt;&lt;/li&gt;
        ...
        &lt;li&gt;&lt;a href="/"&gt;Nav item n&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/nav&gt;
    &lt;div&gt;
      &lt;?php echo $page-&gt;content; ?&gt;
    &lt;/div&gt;
    &lt;footer&gt;
      footer message here
    &lt;/footer&gt;
  &lt;/body&gt;
  &lt;?php echo $page-&gt;foot; ?&gt;
&lt;/html&gt;</pre>
<p>page.php:</p>
<pre>&lt;?php
$page-&gt;title    = "Hello, world";
$page-&gt;template = "template.php";
?&gt;
&lt;?php ob_start(); /* head   */ ?&gt;
  &lt;meta name="description" content="description here"&gt;
&lt;?php $page-&gt;head = ob_get_clean(); 

?&gt;
&lt;?php ob_start(); /* content*/ ?&gt;
  &lt;h1&gt;The Page Title&lt;/h1&gt;
  &lt;p&gt;The article goes here&lt;/p&gt;
&lt;?php $page-&gt;content = ob_get_clean(); 

?&gt;
&lt;?php ob_start(); /* foot   */ ?&gt;
  &lt;script type="text/javascript"&gt; ... /* page specific script */ &lt;/script&gt;
&lt;?php $page-&gt;foot = ob_get_clean(); 

?&gt;
&lt;?php include_once $page-&gt;template ?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://antanova.com/blog/code-bits/asp-net-style-master-pages-in-php/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Code bits: PHP date year box script</title>
		<link>http://antanova.com/blog/code-bits/php-date-year-box-script</link>
		<comments>http://antanova.com/blog/code-bits/php-date-year-box-script#comments</comments>
		<pubDate>Thu, 13 Nov 2008 15:44:00 +0000</pubDate>
		<dc:creator>Jason C</dc:creator>
				<category><![CDATA[Code-bits]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://antanova.wordpress.com/2008/11/13/code-bits-php-date-year-box-script/</guid>
		<description><![CDATA[Code bits: PHP year box script. Create a dropdown form box listing all years from a certain date to the current year.]]></description>
			<content:encoded><![CDATA[<p>Creating a warranty registration form for the proud owners of a new LCD panel should have been a very straightforward job. Well, actually it was, but that sort of interrupts the flow of this post a bit, so I’ll skim over that inconvenient fact.</p>
<p>For the ‘date of purchase’ field, I simply added the day and months items as <code>&lt;select&gt;</code> form controls. Then I got to the ‘year’ box, and realised that soon we’ll be leaving <a href="http://en.wikipedia.org/wiki/2008">2008</a> behind like a piece of temporal rubbish, and embracing the glistening newborn that will be 2009. I know the client wouldn’t really appreciate having to come back to me a month after his site goes live just so I can add a new year to the form, so I decided on the only sensible course of action a <a href="http://www.antanova.com/">quality web designer</a> like me could take, and made a super-simple php script to write the year into the form.</p>
<p>Here’s the php function:</p>
<blockquote>
<pre><code>function writePurchaseYear()
{
    $currentDate = getDate();
    $currentYear = $currentDate['year'];
    $startYear = 2008;
    $output = "&lt;option value=\"2008\"&gt;2008&lt;/option&gt;\n";

    if($currentYear - $startYear &gt; 0)
    {
        for($i = $currentYear; $i &gt;= $startYear; $i--)
        {
            $output = $output . "&lt;output value=\"$i\"&gt;$i&lt;/option&gt;\n";
        }
    }
    echo $output;
}

</code></pre>
</blockquote>
<p>So, put that somewhere on the page that’s going to use it, and then, where you need the actual form control to be on the page, you need to put:</p>
<blockquote>
<pre><code>&lt;select name="purchaseyear" id="purchaseyear"&gt;
    &lt;option selected&gt;----&lt;/option&gt;
    &lt;?php writePurchaseYear();?&gt;
&lt;/select&gt;

</code></pre>
</blockquote>
<p>So there you have it. HTH, and all that.</p>
]]></content:encoded>
			<wfw:commentRss>http://antanova.com/blog/code-bits/php-date-year-box-script/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
