<?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>web2.0goodies.com &#187; hacks</title>
	<atom:link href="http://web2.0goodies.com/blog/category/hacks/feed/" rel="self" type="application/rss+xml" />
	<link>http://web2.0goodies.com/blog</link>
	<description>Tips, Tricks, and How To's for Web 2.0</description>
	<lastBuildDate>Tue, 03 Jan 2012 05:34:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>So you want PHP Templates, eh?</title>
		<link>http://web2.0goodies.com/blog/hacks/so-you-want-a-php-template-eh/</link>
		<comments>http://web2.0goodies.com/blog/hacks/so-you-want-a-php-template-eh/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 05:15:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[100 Weeks of PHP]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://web2.0goodies.com/blog/?p=60</guid>
		<description><![CDATA[PHP Templates! Everyone wants them, some people try to provide them to others, but deep down inside, you all know smarty isn&#8217;t the way to go&#8230; Allow me to show you a better way. Just use PHP! Yes, that&#8217;s right! PHP is almost designed from the ground up natively support templates! Here&#8217;s the secret&#8230; When [...]]]></description>
			<content:encoded><![CDATA[<p>PHP Templates!  Everyone wants them, some people try to provide them to others, but deep down inside, you all know smarty isn&#8217;t the way to go&#8230;  Allow me to show you a better way.</p>
<p>Just use PHP!  Yes, that&#8217;s right!  PHP is almost designed from the ground up natively support templates!</p>
<p>Here&#8217;s the secret&#8230;  When you include a php file (using the include(&#8220;somefile.php&#8221;) method, the php code inside the included file has the same variable scope as the code block that included it&#8230;  So&#8230;  Take the following two files&#8230;.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">(index.php)
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
  go<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">function</span> go<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Hi There!&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_view.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">(my_view.php)
&lt;html&gt;
&lt;body&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$a</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>The output would be:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Hi There<span style="color: #339933;">!</span></pre></div></div>

<p>If you&#8217;re a noob, another name for this (if you make extra effort to not put anything but loops, and echos in your template) is MVC (Model View Controller).  While it isn&#8217;t a complete implementation, it&#8217;s a really really good start and makes writing and maintaining a site WAY easier.  Cake PHP uses this approach for it&#8217;s views (aka templates) as well.  Java uses this, but instead of the &#8220;view&#8221; using the local variables where a page is displayed, the data you want the view (or jsp page in java) to have access to are put in the request object as an &#8220;attribute&#8221;.</p>
<p>I, personally, put the variables I want to use in a &#8220;template&#8221; (aka &#8220;view&#8221;) in a global array ($GLOBALS['params']['name'] = &#8220;bob&#8221;;)  It isn&#8217;t the best practice, because some part of your code far away could write to this and mess something up, but for simple sites, I find it quick and easy.  </p>
<p>Of course, if you REALLY want a templating system, you could use SMARTY.  (Blech!)  But, I really recommend you just get used the to the echo statements and use php to render templates.</p>
<p>So, some sample code from a site of mine is:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>BASE_FS_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/classes/BookService.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'Research'</span><span style="color: #339933;">:</span>
		<span style="color: #000088;">$book</span> <span style="color: #339933;">=</span> BookService<span style="color: #339933;">::</span><span style="color: #004000;">importBook</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ean'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$_GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'params'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'book'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$book</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span>BASE_FS_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/views/pages/research.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'mark_not_sellable'</span><span style="color: #339933;">:</span>
		<span style="color: #000088;">$book</span> <span style="color: #339933;">=</span> BookService<span style="color: #339933;">::</span><span style="color: #004000;">importBook</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ean'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sellable</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'no'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$_GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'params'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'msg'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Book Marked As Not Sellable.'</span><span style="color: #339933;">;</span>
		show_details<span style="color: #009900;">&#40;</span><span style="color: #000088;">$book</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'mark_not_available'</span><span style="color: #339933;">:</span>
		<span style="color: #000088;">$book</span> <span style="color: #339933;">=</span> BookService<span style="color: #339933;">::</span><span style="color: #004000;">importBook</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ean'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">available</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'no'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$_GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'params'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'msg'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Book Marked As Not Available.'</span><span style="color: #339933;">;</span>
		show_details<span style="color: #009900;">&#40;</span><span style="color: #000088;">$book</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'details'</span><span style="color: #339933;">:</span>
		<span style="color: #000088;">$book</span> <span style="color: #339933;">=</span> BookService<span style="color: #339933;">::</span><span style="color: #004000;">importBook</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ean'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		show_details<span style="color: #009900;">&#40;</span><span style="color: #000088;">$book</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
		<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span>BASE_FS_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/views/pages/research.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> show_details<span style="color: #009900;">&#40;</span><span style="color: #000088;">$book</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$_GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'params'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'book'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$book</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span>BASE_FS_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/views/pages/details.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And the &#8220;view&#8221; for this code (details.php) is:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;body style=&quot;width:950px; margin: 0 auto; text-align: left;&quot; class=&quot; yui-skin-sam&quot;&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
			<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span>BASE_FS_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/views/pieces/menu_and_js.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
		&lt;div style=&quot;text-align: center;&quot;&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'params'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'msg'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;/div&gt;
&nbsp;
		&lt;table&gt;
		 &lt;tr&gt;
		  &lt;td&gt;
			&lt;h1&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'params'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'book'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h2&gt;
			&lt;ul&gt;
			&lt;li&gt;Ean: <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'params'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'book'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ean</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/li&gt;
			&lt;li&gt;Available: <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'params'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'book'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">available</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/li&gt;
			&lt;li&gt;Imported: <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'params'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'book'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">import_date</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/li&gt;
			&lt;li&gt;Cost: <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'params'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'book'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cost</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/li&gt;
			&lt;li&gt;Change In Inventory: <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'params'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'book'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">change_in_inventory</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/li&gt;
			&lt;/ul&gt;
			&lt;h2&gt;Urls&lt;/h2&gt;
                         (More Code That's been removed for this example)</pre></div></div>

<p>Anyways, there are LOTs of templating engines out there you can use instead, but I would discourage it.  This is the fastest, simplest, most powerful way to do templates (IMO).</p>
]]></content:encoded>
			<wfw:commentRss>http://web2.0goodies.com/blog/hacks/so-you-want-a-php-template-eh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>min-height CSS Hack</title>
		<link>http://web2.0goodies.com/blog/hacks/min-height-css-hack/</link>
		<comments>http://web2.0goodies.com/blog/hacks/min-height-css-hack/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 00:38:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[html]]></category>

		<guid isPermaLink="false">http://web2.0goodies.com/blog/?p=36</guid>
		<description><![CDATA[I needed a min-height hack for css that worked everywhere. I searched for a while, and found this link: http://www.greywyvern.com/code/min-height-hack. It works as advertised, just checkout the tabs on propertynut.com]]></description>
			<content:encoded><![CDATA[<p>I needed a min-height hack for css that worked everywhere.  I searched for a while, and found this link: <a href="http://www.greywyvern.com/code/min-height-hack">http://www.greywyvern.com/code/min-height-hack</a>.  It works as advertised, just checkout the tabs on <a href="https://propertynut.com/find.aspx?r=details&#038;propertyid=5445#">propertynut.com</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://web2.0goodies.com/blog/hacks/min-height-css-hack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

