<?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>amptools &#187; Zend Framework</title>
	<atom:link href="http://www.amptools.net/tag/zend-framework/feed" rel="self" type="application/rss+xml" />
	<link>http://www.amptools.net</link>
	<description>Simplify your life.</description>
	<lastBuildDate>Sat, 08 May 2010 07:40:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Zend Framework Image Captcha</title>
		<link>http://www.amptools.net/blog/zend-framework-image-captcha</link>
		<comments>http://www.amptools.net/blog/zend-framework-image-captcha#comments</comments>
		<pubDate>Wed, 24 Jun 2009 19:19:40 +0000</pubDate>
		<dc:creator>Michael Herndon</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[image captcha]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.amptools.net/?p=110</guid>
		<description><![CDATA[
The Zend Framework documentation lacks when it comes to showing the ins of out of some of its components, the Zend Framework captcha seems to fall under that category.  You would think there would be a ton of useful blog posts and if there are useful posts, I don&#8217;t think google is catching them. [...]]]></description>
			<content:encoded><![CDATA[<img class='gravatar' style='float: left; margin-right: 10px; border: none;' src='http://www.gravatar.com/avatar.php?gravatar_id=899a978b0f02774a965aec11eeb0b8f4&amp;default=http://amppotls.net' alt='No Gravatar' width=48 height=48/><p>
The Zend Framework documentation lacks when it comes to showing the ins of out of some of its components, the <a href="http://framework.zend.com/manual/en/zend.captcha.operation.html" rel="tag">Zend Framework captcha</a> seems to fall under that category.  You would think there would be a ton of useful blog posts and if there are useful posts, I don&#8217;t think google is catching them.  I did find some useful code on this blog, <a href="http://blog.sankhomallik.com/2008/12/17/tutorial-using-zend_captcha_image/" rel="tag">sankhomalik&#8217;s tutorial on using the zend image captcha</a>. It does make some decent notes, so please go read this post first (and thank him, cause so far he has the best notes on the ZF captcha thus far), but the code did not seem to work with the current version of Zend that I have which is currently version 1.7.8. The other post is using some kind of Iterator and expecting the zend namespace to have a getIterator method, for some reason this was not working for me.
</p>
<p>
Here is the modified/refactored version that creates a static wrapper Captcha class using the image captcha.  To reiterate what the other blog says, Make sure you have GD enabled, make sure you have a font file, make sure you have the file paths pointing to the right place, and make sure you have the right permissions for the folders that contain the images and font file.
</p>
<h4>PHP Captcha Class</h4>
<pre class="brush: php;">
class Capatcha
{

	/**
	 * validates the last image captcha that was created
	 * and put into the current session.
	 *
	 * @param string $postPrefix  the prefix of the post value i.e. 'captcha[id]'
	 * @return boolean
	 */
	public static function validate($postPrefix = &quot;captcha&quot;)
	{
		$captcha = $_POST[$postPrefix];
        	$captchaId = $captcha['id'];
        	$captchaInput = $captcha['input'];
        	$captchaSession = new Zend_Session_Namespace('Zend_Form_Captcha_' . $captchaId);

        	$captchaWord =   $captchaSession-&gt;word;
        	if( $captchaWord )
        		return $captchaInput == $captchaWord;
       		return false;
	}

	/**
	 * generates the captcha image and returns the image id.
	 *
	 * @param string $postPrefix  the prefix of the post value i.e. 'captcha[id]'
	 * @return string
	 */
	public static function generate($postPrefix = &quot;captcha&quot;)
	{
		// replace the path/to with the correct path...
		// same with /images/captcha
		$captcha = new Zend_Captcha_Image(array(
		    'name' =&gt; $postPrefix,
		    'wordLen' =&gt; 6,
		    'timeout' =&gt; 600,
			'font' =&gt; &quot;path/to/IMPACT.TTF&quot;,
			'imgdir' =&gt; &quot;path/to/images/captcha&quot;,
			'imgurl' =&gt; &quot;/images/captcha&quot;
		));

		return $captcha-&gt;generate();
	}
}
</pre>
<h4>PHP ZF Controller</h4>
<pre class="brush: php;">
// in your action in the controller,
// it would look like some variation of this
if($this-&gt;getRequest()-&gt;isPost())
{
	if(!Capatcha::validate())
        {
        	$id = Capatcha::generate();
        	$this-&gt;view-&gt;captcha = $id;
        	$this-&gt;view-&gt;message = &quot;captcha was invalid&quot;;
        	return;
        } else {
               $this-&gt;view-&gt;message = &quot;saved!&quot;;
        }
}
else
{
        $this-&gt;view-&gt;message =&quot;&quot;;
        $id = Capatcha::generate();
        $this-&gt;view-&gt;captcha = $id;
}
</pre>
<h4>XHTML View</h4>
<pre class="brush: php;">

&lt;!-- above your form using with short tags on --&gt;
&lt;div class=&quot;error&quot;&gt;&lt;?= $this-&gt;message ?&gt;&lt;/div&gt;

&lt;!-- somewhere in your form --&gt;
	&lt;img src=&quot;/images/captcha/&lt;?= $this-&gt;captcha ?&gt;.png&quot; alt=&quot;captcha&quot; /&gt;
	&lt;input type=&quot;text&quot; name=&quot;captcha[input]&quot; value=&quot;&quot; /&gt;
	&lt;input type=&quot;hidden&quot; name=&quot;captcha[id]&quot; value=&quot;&lt;?= $this-&gt;captcha ?&gt;&quot; /&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.amptools.net/blog/zend-framework-image-captcha/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTTP GET vs POST in the Zend Framework</title>
		<link>http://www.amptools.net/blog/http-get-vs-post-in-the-zend-framework</link>
		<comments>http://www.amptools.net/blog/http-get-vs-post-in-the-zend-framework#comments</comments>
		<pubDate>Thu, 11 Jun 2009 14:32:27 +0000</pubDate>
		<dc:creator>Michael Herndon</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.amptools.net/?p=93</guid>
		<description><![CDATA[
As most web developers know there is a difference between HTTP GET and HTTP POST and sometimes you end up using a combination of these items and take precedence depending on what are you are trying to accomplish.  In the Zend Framework, when working with controllers there is a Zend_Controller_Request_Http object used in conjunction [...]]]></description>
			<content:encoded><![CDATA[<img class='gravatar' style='float: left; margin-right: 10px; border: none;' src='http://www.gravatar.com/avatar.php?gravatar_id=899a978b0f02774a965aec11eeb0b8f4&amp;default=http://amppotls.net' alt='No Gravatar' width=48 height=48/><p>
As most web developers know there is a difference between HTTP GET and HTTP POST and sometimes you end up using a combination of these items and take precedence depending on what are you are trying to accomplish.  In the Zend Framework, when working with controllers there is a <a href="http://framework.zend.com/manual/en/zend.controller.request.html" rel="tag">Zend_Controller_Request_Http</a> object used in conjunction with controllers.   The object has useful methods like determining what kind of HTTP Request it is (isPost, isXmlHttpRequest, isGet, etc), getting various request variables (_getParam, getParams, getPost,etc).
</p>
<p>
While working on a search page for a client, I came across a need to get POST values which could sometimes also be in the query string already, but needed the HTTP POST variables to take precedence in being loaded. When using <span class="code">$this->_request->_getParam()</span> inside of the controller, the HTTP GET values were taking precedence.  The reason why:  there is no <span class="code">$this->_request->getGet()</span> method on the request object, HTTP GET data must be acquired through <span class="code">$this->_request->_getParam()</span> or by calling for the property (which invokes the magic method __get on the request object).  The _getParam() method always checks GET data first.  However there is a <span class="code">$this->_request->getPost()</span> method which can be used to retrieved the post values.
</p>
<h4>PHP</h4>
<pre class="brush: php;">
// in the controller action method....
// too long to use a ternary.

// TIP:
// technically $this-&gt;_request-&gt;search should be the same as
// $this-&gt;_request-&gt;getPost('search');
if($this-&gt;_request-&gt;isPost())
	$params = $this-&gt;_request-&gt;getPost('search'); // HTTP POST
else
	$params = $this-&gt;_getParam(&quot;search&quot;, array()); // HTTP GET

// there is no $this-&gt;getGet('search')
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.amptools.net/blog/http-get-vs-post-in-the-zend-framework/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun Times with Partial Loops in Zend Framework</title>
		<link>http://www.amptools.net/blog/fun-times-with-partial-loops-in-zend-framework</link>
		<comments>http://www.amptools.net/blog/fun-times-with-partial-loops-in-zend-framework#comments</comments>
		<pubDate>Thu, 11 Jun 2009 13:45:13 +0000</pubDate>
		<dc:creator>Michael Herndon</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[midori-php]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.amptools.net/?p=87</guid>
		<description><![CDATA[While working with the Zend Framework and partial loops, I ran into a few issues.  One was not getting the data to load, which was easily solved after looking at partials documentation. Make sure you set the object key in the controller for the partial loop. The other issue of trying to pass local [...]]]></description>
			<content:encoded><![CDATA[<img class='gravatar' style='float: left; margin-right: 10px; border: none;' src='http://www.gravatar.com/avatar.php?gravatar_id=899a978b0f02774a965aec11eeb0b8f4&amp;default=http://amppotls.net' alt='No Gravatar' width=48 height=48/><p>While working with the Zend Framework and partial loops, I ran into a few issues.  One was not getting the data to load, which was easily solved after looking at <a href="http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.partial" rel="tag">partials documentation</a>. Make sure you set the object key in the controller for the partial loop. The other issue of trying to pass local variables into the partial loop took time to see there was really no current answer without extending or creating a new helper, or the evil global.</p>
<h4>PHP</h4>
<pre class="brush: php;">
// in the action method
global $otherVariable;
$otherVariable = &quot;should be the same through each iteration&quot;;
$this-&gt;view-&gt;partialLoop()-&gt;setObjectKey('model');
$this-&gt;view-&gt;paginator = Zend_Paginator::factory($array); //etc

// in the view
&lt;?= $this-&gt;partialLoop('path/to/_partial.phtml', $this-&gt;paginator) ?&gt;

// in the _partial.phtml
&lt;?php
      $model = $this-&gt;model
      global $otherVariable; // just seems so hackish to have to do this.
?&gt;
</pre>
<p>I have already added a <a href="http://github.com/michaelherndon/midori-php/issues#issue/3">task</a> to <a href="/projects/midori-php" rel="tag">Midori PHP </a> to extend the Partial Loop Helper to overcome the lack of the ability to pass in local variables to the partial loop.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.amptools.net/blog/fun-times-with-partial-loops-in-zend-framework/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->