<?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>amnuts &#187; zend_view</title>
	<atom:link href="http://blog.amnuts.com/tag/zend_view/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.amnuts.com</link>
	<description>php projects, javascript, and... stuff.</description>
	<lastBuildDate>Fri, 27 Jan 2012 21:15:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>QrCode view helper</title>
		<link>http://blog.amnuts.com/2010/02/10/qrcode-view-helper/</link>
		<comments>http://blog.amnuts.com/2010/02/10/qrcode-view-helper/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 16:36:16 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[qrcode]]></category>
		<category><![CDATA[zend_view]]></category>
		<category><![CDATA[zend_view_helper]]></category>

		<guid isPermaLink="false">http://blog.amnuts.com/?p=166</guid>
		<description><![CDATA[You see QrCodes popping up every now and again on sites, in publications and the like. I think they can be a very handy way for people with cameras on their phones to get a url or other content on to their phone very easily. (I&#8217;m thinking more about those people without iPhones or full [...]]]></description>
			<content:encoded><![CDATA[<p>You see QrCodes popping up every now and again on sites, in publications and the like.  I think they can be a very handy way for people with cameras on their phones to get a url or other content on to their phone very easily.  (I&#8217;m thinking more about those people without iPhones or full keyboards, of course!)</p>
<p>If you&#8217;ve never seen a QrCode before, it looks something like this:</p>
<p><img src="http://chart.apis.google.com/chart?cht=qr&amp;chl=http%3A%2F%2Fblog.amnuts.com%2F&amp;chld=M|0&amp;chs=100x100" alt="QR Code image" /></p>
<p>Now how cool would it be to be able to generate that automatically for each page on your site and allow people to be able bookmark that site on their phone?  Well, <strong><em>I</em></strong> think it&#8217;d be pretty cool!  So I came up with a very simple ZF view helper to do it for me.</p>
<p><span id="more-166"></span>This is the view helper code:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php

/**
 * Output a QR code block.
 *
 * Currently, only via Google Chart API is supported, but it has
 * room to add other sources of qrcode generation.
 *
 * @category   Amnuts
 * @package    Amnuts_View
 * @subpackage Amnuts_View_Helper
 */
class Amnuts_View_Helper_QrCode extends Zend_View_Helper_Abstract
{
    protected $template = '
        &lt;div class=&quot;qrcode&quot;&gt;
            &lt;p&gt;Bookmark this page on your mobile&lt;/p&gt;
            &lt;img src=&quot;%s&quot; alt=&quot;QR Code image&quot; /&gt;
            &lt;p class=&quot;hint&quot;&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/QR_Code&quot;&gt;What is this?&lt;/a&gt;&lt;/p&gt;
        &lt;/div&gt;
        ';

    /**
     * Constructor.
     *
     * @return Amnuts_View_Helper_QrCode
     */
    public function qrCode($template = null)
    {
        if (null !== $template) {
            $this-&gt;template = $template;
        }
        return $this;
    }

    /**
     * Generate the QR code image via Google's Chart API.
     *
     * @param  array  $params
     * @return string
     */
    public function google($params = array())
    {
        $default = array(
            'text'       =&gt; $_SERVER['SCRIPT_URI'],
            'size'       =&gt; '100x100',
            'correction' =&gt; 'M',
            'margin'     =&gt; 0
        );
        $params = array_merge($default, $params);

        $params['text']   = urlencode($params['text']);
        $params['margin'] = (int)$params['margin'];
        if (!in_array($params['correction'], array('L', 'M', 'Q', 'H'))) {
            $params['correction'] = 'M';
        }
        if (!preg_match('/^\d+x\d+$/', $params['size'])) {
            $params['size'] = '100x100';
        }

        $url = &quot;http://chart.apis.google.com/chart?cht=qr&amp;chl={$params['text']}&quot;
             . &quot;&amp;chld={$params['correction']}|{$params['margin']}&quot;
             . &quot;&amp;chs={$params['size']}&quot;;
        return sprintf($this-&gt;template, $url);
    }
}
</pre>
<p>As it&#8217;s a view helper, it&#8217;s very simple to use within your view.  Just do something like:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php echo $this-&gt;qrCode()-&gt;google(); ?&gt;</pre>
<p>If you want to change the default template for one instance, you can do that such as:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php echo $this-&gt;qrCode('&lt;li&gt;&lt;img src=&quot;%s&quot; /&gt;&lt;/li&gt;')-&gt;google(); ?&gt;</pre>
<p>And, of course, you can change the parameters that the QrCode uses, too.  By default, if you don&#8217;t supply the &#8216;text&#8217; parameter then it will use the script uri.  But you could change that with something like:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php echo $this-&gt;qrCode()-&gt;google(array('text' =&gt; 'Visit my site at: http://blog.amnuts.com/')); ?&gt;</pre>
<p>There are other options as view helper code shows.  But this should get you started on easily using QrCodes on your own site.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.amnuts.com/2010/02/10/qrcode-view-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework hidden gems</title>
		<link>http://blog.amnuts.com/2009/03/24/zend-framework-hidden-gems/</link>
		<comments>http://blog.amnuts.com/2009/03/24/zend-framework-hidden-gems/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 17:16:20 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[streams]]></category>
		<category><![CDATA[zend_view]]></category>
		<category><![CDATA[zend_view_stream]]></category>

		<guid isPermaLink="false">http://blog.amnuts.com/?p=133</guid>
		<description><![CDATA[Sometimes you come across hidden little gems in the Zend Framework that save you time, even if that&#8217;s just down to the amount of text you need to type. The Zend_View holds one of these little gems&#8230; Did you know that you can use the short php open tags and echo tag in your view [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you come across hidden little gems in the Zend Framework that save you time, even if that&#8217;s just down to the amount of text you need to type.  The Zend_View holds one of these little gems&#8230;</p>
<p>Did you know that you can use the short php open tags and echo tag in your view scripts, and you don&#8217;t even need to have this turned on in the php.ini file?</p>
<p>So you can have things like:</p>
<p><code>&lt;? $this->viewHelper(); ?&gt;</code></p>
<p>and:</p>
<p><code>&lt;?= $this->variable; ?&gt;</code></p>
<p>instead of:</p>
<p><code>&lt;?php $this->viewHelper(); ?&gt;</code><br />
<code>&lt;?php echo $this->variable; ?&gt;</code></p>
<p>Might not seem a lot, but when you have a lot of view scripts to write then you can save quite a few key strokes.</p>
<p>It&#8217;s able to do this, even if you have short_tags off (as it should be!) because Zend_View uses a stream to open and seek through the view script &#8211; Zend_View_Stream.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.amnuts.com/2009/03/24/zend-framework-hidden-gems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

