<?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>Chris Antoine &#187; Zend Framework</title>
	<atom:link href="http://www.chrisantoine.net/category/zend-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisantoine.net</link>
	<description>PHP / MySQL / JavaScript / Ajax Development.</description>
	<lastBuildDate>Fri, 13 Nov 2009 03:11:00 +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>Prettier Accessible Forms with Zend Form and Zend Config</title>
		<link>http://www.chrisantoine.net/2008/07/15/prettier-accessible-forms-with-zend-form-and-zend-config/</link>
		<comments>http://www.chrisantoine.net/2008/07/15/prettier-accessible-forms-with-zend-form-and-zend-config/#comments</comments>
		<pubDate>Tue, 15 Jul 2008 04:23:10 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Prettier Accessible Forms]]></category>
		<category><![CDATA[Zend Config]]></category>
		<category><![CDATA[Zend Form]]></category>

		<guid isPermaLink="false">http://www.chrisantoine.net/?p=22</guid>
		<description><![CDATA[When I first started working with Zend Framework and showed a designer the output from Zend Form we had a few days of conversations back and forth and researched on whether or not the dl/dt setup was going to be sufficient for what we wanted and also &#8220;correct usage&#8221;.
While working through our first project we [...]]]></description>
			<content:encoded><![CDATA[<p>When I first started working with <a title="Zend Framework" href="http://framework.zend.com" target="_blank">Zend Framework</a> and showed a designer the output from <a title="Zend Form" href="http://framework.zend.com/manual/en/zend.form.html" target="_blank">Zend Form</a> we had a few days of conversations back and forth and researched on whether or not the dl/dt setup was going to be sufficient for what we wanted and also &#8220;correct usage&#8221;.</p>
<p>While working through our first project we ran into issues with this structure of forms.  I didn&#8217;t run into any problems but in order to stop the complaints from the designers in our office I decided to work on getting <a title="Zend Form" href="http://framework.zend.com/manual/en/zend.form.html" target="_blank">Zend Form</a> to generate forms in the style laid out at <a title="Prettier Accessible Forms" href="http://www.alistapart.com/articles/prettyaccessibleforms" target="_blank">A List Apart.</a></p>
<p>I didn&#8217;t figure this would really be all that difficult because most of the documentation for <a title="Zend Framework" href="http://framework.zend.com" target="_blank">Zend Framework</a> fairly good.  Little did I know that the documentation and examples for <a title="Zend Form" href="http://framework.zend.com/manual/en/zend.form.html" target="_blank">Zend Form</a> with <a title="Zend Config" href="http://framework.zend.com/manual/en/zend.config.html" target="_blank">Zend Config</a> were fairly hard to find.  When I did find documentation the decorators stilled confused me for a while.  Then everything just seemed to click one day and I was successful in getting exactly what I wanted.  Now I don&#8217;t have designers complaining anymore because they have forms structured exactly the way they want(Sorry Rob <img src='http://www.chrisantoine.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ).  In order to get the results I wanted I ended up with a form defined in my ini file like the following:</p>
<pre>[signInForm]
form.id = "signInForm"
form.method = "post"
form.action = "/sign-in/"

; Form Decorators
form.disableLoadDefaultDecorators = true
form.decorators.formElements.decorator = "FormElements"
form.decorators.description.decorator = "Description"
form.decorators.form.decorator = "Form"

; Global Element Decorators
form.elementDecorators.decorator = "ViewHelper"
form.elementDecorators.error.decorator = "Errors"
form.elementDecorators.description.decorator = "Description"
form.elementDecorators.label.decorator = "Label"
form.elementDecorators.formElements.decorator = "HtmlTag"
form.elementDecorators.formElements.options.tag = "li"

; Group Decorators
form.displayGroupDecorators.decorator = "FormElements"
form.displayGroupDecorators.formElements.decorator = "HtmlTag"
form.displayGroupDecorators.formElements.options.tag = "ol"
form.displayGroupDecorators.fieldset.decorator = "Fieldset"

; Form Groups
form.displayGroups.signinGroup.elements.username    = "username"
form.displayGroups.signinGroup.elements.password    = "password"
form.displayGroups.signinGroup.elements.rememberMe  = "rememberMe"

form.displayGroups.submitGroup.elements.submit = "submit"

; username element
form.elements.username.type = "text"
form.elements.username.options.validators.notempty.validator = "NotEmpty"
form.elements.username.options.validators.notempty.breakChainOnFailure = true
form.elements.username.options.validators.strlen.validator = "StringLength"
form.elements.username.options.validators.strlen.options.min = 6
form.elements.username.options.validators.strlen.options.max = 20
form.elements.username.options.required = true
form.elements.username.options.label = "Username:"

; password element
form.elements.password.type ="password"
form.elements.password.options.validators.notempty.validator = "NotEmpty"
form.elements.password.options.validators.notempty.breakChainOnFailure = true
form.elements.password.options.validators.strlen.validator = "StringLength"
form.elements.password.options.validators.strlen.options.min = "6"
form.elements.password.options.required = true
form.elements.password.options.label = "Password:"

; remember me element
form.elements.rememberMe.type = "checkbox"
form.elements.rememberMe.options.label = "Remember Me?"

; login button element
form.elements.submit.type = "button"
form.elements.submit.options.name = "SignIn"
form.elements.submit.options.value = "Sign In"
form.elements.submit.options.label = "Sign In"</pre>
<p>I hope this helps someone else as I could not find a good solid example of how to get this working.  If anyone has any feedback on a better way of handling this let me know in the comments.<br />
Thanks,<br />
Chris</p>
<p>Update<br />
I updated &#8220;FieldSet&#8221; to &#8220;Fieldset&#8221; as that has changed since I wrote this post.  Thanks for the message about the error!<br />
Chris</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisantoine.net/2008/07/15/prettier-accessible-forms-with-zend-form-and-zend-config/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>UniqueField Validate Helper</title>
		<link>http://www.chrisantoine.net/2008/07/14/uniquefield-validate-helper/</link>
		<comments>http://www.chrisantoine.net/2008/07/14/uniquefield-validate-helper/#comments</comments>
		<pubDate>Tue, 15 Jul 2008 03:56:30 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Helpers]]></category>
		<category><![CDATA[Validate Helper]]></category>

		<guid isPermaLink="false">http://www.chrisantoine.net/?p=21</guid>
		<description><![CDATA[The last 4 projects that I have created I have built using Zend Framework.  The more I use it the more I find things that make my life easier.  My first shot at creating a validator was for checking whether or not a username is unique.  .  I need this functionality [...]]]></description>
			<content:encoded><![CDATA[<p>The last 4 projects that I have created I have built using Zend Framework.  The more I use it the more I find things that make my life easier.  My first shot at creating a validator was for checking whether or not a username is unique.  .  I need this functionality in pretty much every application I build.  I realized while writing the same code again(more or less a copy and paste but still <img src='http://www.chrisantoine.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ) in the 3 or 4th project that I should take advantage of the custom validators that I had read about but hadn&#8217;t tackled.</p>
<p>The following is probably revision 2 of the original idea.  I realized after writing it the first time I should have made it more generic so I could use it on multiple fields without changing anything except the properties in the config ini for each form field.</p>
<p>To add the validator to a field using Zend Config you would do the following:</p>
<pre>
        form.elements.email.options.validators.uniqueField.validator = "uniqueField"
        form.elements.email.options.validators.uniqueField.options.modelName = "Notification"
        form.elements.email.options.validators.uniqueField.options.fieldname = "notification_email"
</pre>
<pre>
<code class="php">
< ?php
class Robyn_Validate_UniqueField extends Zend_Validate_Abstract
{
    /**
     * @var String
     */
    const NOT_UNIQUE = 'error';

    /**
     * @var String
     */
    protected $_modelName = 'User';

    /**
     * @var String
     */
    protected $_fieldName = 'user_username';

    /**
     * @var array
     */
    protected $_messageTemplates = array(
                                         self::NOT_UNIQUE => 'The data given is not unique.'
                                         );

    /**
     * Sets validator options
     *
     * @param  string $modelName
     * @param  string $fieldName
     * @return void
     */
    public function __construct($modelName = 'User', $fieldName = 'user_username')
    {
        $this->setModelName($modelName);
        $this->setFieldName($fieldName);
    }

    /**
     * Defined by Zend_Validate_Interface
     *
     * Returns true if and only if the email address is found to NOT have a match in the fieldname in the model specified
     *
     * @param Array $value
     * @param Array $request
     * @return boolean
     */
    public function isValid($value, $request = null)
    {
        // Set the value
        $value = (string) $value;
        $this->_setValue($value);

        // Get our model and do a search for that username
        $table = new $this->_modelName();
        $result = $table->fetchAll($table->select()->where($this->_fieldName . ' = ?', $value))->toArray();

        // Check to see if we got any results
        if (count($result) == 0) {
            return true;
        }

        $this->_error(self::NOT_UNIQUE);
        return false;
    }

    /**
     * Set the model name.
     *
     * @param string $modelName
     * @return Zend_Validate_UniqueUsername Provides a fluent interface
     */
    public function setModelName($modelName)
    {
        $this->_modelName = $modelName;

        return $this;
    }

    /**
     * Set the field name.
     *
     * @param string $fieldName
     * @return Zend_Validate_UniqueUsername Provides a fluent interface
     */
    public function setFieldName($fieldName)
    {
        $this->_fieldName = $fieldName;

        return $this;
    }
}
</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisantoine.net/2008/07/14/uniquefield-validate-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend History Action Helper(Codeutopia)</title>
		<link>http://www.chrisantoine.net/2008/07/14/zend-history-action-helpercodeutopia/</link>
		<comments>http://www.chrisantoine.net/2008/07/14/zend-history-action-helpercodeutopia/#comments</comments>
		<pubDate>Tue, 15 Jul 2008 03:42:31 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.chrisantoine.net/?p=17</guid>
		<description><![CDATA[Back a few weeks ago I came across a very handy Zend Framework Helper for tracking a user’s browsing history(here).  I was needing something very similar for a project I was working on, actually I need it for most projects I work on.  While implementing it I noticed there were some things that I wanted [...]]]></description>
			<content:encoded><![CDATA[<p>Back a few weeks ago I came across a very handy <a title="Zend Framework Helpers" onclick="javascript:pageTracker._trackPageview ('/outbound/framework.zend.com');" href="http://framework.zend.com/manual/en/zend.controller.actionhelpers.html" target="_blank">Zend Framework Helper</a> for tracking a user’s browsing history(<a title="Codeutopia" onclick="javascript:pageTracker._trackPageview ('/outbound/codeutopia.net');" href="http://codeutopia.net/blog/2008/03/07/tracking-the-users-browsing-history-with-php/" target="_blank">here</a>).  I was needing something very similar for a project I was working on, actually I need it for most projects I work on.  While implementing it I noticed there were some things that I wanted to modify in order to get the true functionality I needed.</p>
<p>The modifications were pretty basic in that the code was tracking ALL requests and there are a few requests that I did not want to track(namely Ajax and page reloads).  By not tracking these requests I feel I get a much more accurate representation of the path the user is following through the application.  The one thing I am still yet to conquer is how to find out if a requests is triggering a 404 page and if so to not track it.  I’m not sure that it is even possible because of when the helper is triggered but I haven’t delved very deep either(just something I want to put in at some point but if you know how let me know in the comments).So without further ado the code:</p>
<pre>
<code class="php">
&lt;?php
Zend_Loader::loadClass('Zend_Controller_Action_Helper_Abstract');
Zend_Loader::loadClass('Zend_Controller_Action_HelperBroker');
Zend_Loader::loadClass('Zend_Session_Namespace');
/**
* This helper tracks the user's browsing history
*
* @copyright 2008 Jani Hartikainen &lt;www.codeutopia.net&gt;
* @author Jani Hartikainen &lt;firstname at codeutopia net&gt;
* @author Chris Antoine &lt;chris@spinweb.net&gt;(Modifications)
*/
class SoulOpinion_Action_Helper_History extends Zend_Controller_Action_Helper_Abstract
{
/**
* @var Zend_Session_Namespace
*/
private $_namespace;

/**
* How many history URLs to track?
*
* @var int
*/
private $_trackAmount = 0;

/**
* Track Ajax Requests?
*
* @var int
*/
private $_ajax = 0;

/**
* Current URL
*
* @var string
*/
private $_currentUrl = null;

/**
* @param int $trackAmount [optional] How many history URLs to track
*/
public function __construct($trackAmount = 5)
{
$this-&gt;setTrackAmount($trackAmount);

$this-&gt;_initSession();
}

/**
* Initialize the history from session
*/
private function _initSession()
{
$this-&gt;_namespace = new Zend_Session_Namespace('Zend_Controller_Action_Helper_History');

// Break out if we don't want to track the request
if ($this-&gt;trackableRequest() == false) {
return true;
}

if (!is_array($this-&gt;_namespace-&gt;history)) {
$this-&gt;_namespace-&gt;history = array();

if(!empty($_SERVER['HTTP_REFERER'])) {
array_unshift($this-&gt;_namespace-&gt;history, $_SERVER['HTTP_REFERER']);
}
} else {
array_splice($this-&gt;_namespace-&gt;history, $this-&gt;_trackAmount);
}
}

public function preDispatch()
{
$urlHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('Url');
$this-&gt;_currentUrl = $urlHelper-&gt;url();

// Break out if we don't want to track the request
if ($this-&gt;trackableRequest() == false) {
return true;
}

if (!is_array($this-&gt;_namespace-&gt;history)) {
$this-&gt;_namespace-&gt;history = array();
}

array_unshift($this-&gt;_namespace-&gt;history, $this-&gt;_currentUrl);
}

/**
* Set how many history URLs to track
*
* @param int $trackAmount
*/
public function setTrackAmount($trackAmount)
{
$this-&gt;_trackAmount = $trackAmount;
}

/**
* Redirects the browser back in history
*
* @param int $amount How many URLs to go back
*/
public function goBack($amount = 1)
{
Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')
-&gt;setPrependBase(false)
-&gt;gotoUrl($this-&gt;_namespace-&gt;history[$amount]);
}

/**
* Returns an URL from history
*
* @param int $amount How many URLs to go back
* @return string
*/
public function getPreviousUrl($amount = 1)
{
return $this-&gt;_namespace-&gt;history[$amount];
}

/**
* Return all previous URLs
*
* @return array
*/
public function getArray()
{
return $this-&gt;_namespace-&gt;history;
}

public function getName()
{
return 'History';
}

/**
* Validate that we want to track the request
*
* @return Boolean
*/
private function trackableRequest()
{
// Decide whether or not we should track Ajax Requests
if ($this-&gt;_ajax == 0) {
Zend_Loader::loadClass('Zend_Controller_Request_Http');
$request = new Zend_Controller_Request_Http();

if ($request-&gt;isXmlHttpRequest()) {
return false;
}
}

// Now we are going to verify the user didn't just reload the page or click the same link.
// No reason to track page reloads.
if ($this-&gt;_currentUrl == $this-&gt;_namespace-&gt;history[0]) {
return false;
}

// Need to come up with a way to check for a 404 error so we don't track bad requests.

return true;
}
}
</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisantoine.net/2008/07/14/zend-history-action-helpercodeutopia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
