<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-11498321</id><updated>2011-11-27T19:07:23.699-05:00</updated><category term='jquery'/><category term='webdev'/><category term='javascript'/><category term='zend framework'/><category term='php'/><category term='prototype'/><title type='text'>Hey, Something Shiny!</title><subtitle type='html'>My random thoughts and realizations.  Mostly on web development.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://weilandaj.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11498321/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://weilandaj.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Andrew</name><uri>http://www.blogger.com/profile/15797267658310961255</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-11498321.post-7352917139199262241</id><published>2010-08-25T10:56:00.000-04:00</published><updated>2010-08-25T10:56:26.552-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='zend framework'/><category scheme='http://www.blogger.com/atom/ns#' term='webdev'/><title type='text'>Custom Form Validators in Zend Framework</title><content type='html'>This problem got me for a few hours the other day and google was barely helpful. &amp;nbsp;So I thought I'd share this.&lt;br /&gt;&lt;br /&gt;When you write a custom validator, you have to tell the form object where to look. &amp;nbsp;I was unable to find a way for the autoloader to find it (please correct me if there is!). &amp;nbsp;I'm not a fan of this syntax because I don't like burying and hard coding path information this deep into the code, especially with a framework as configurable as Zend.&lt;br /&gt;&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Let's say we have a validator and it's located in APPLICATION_PATH/shiny/Validate/Omg.php&lt;br /&gt;&lt;br /&gt;&lt;pre class="php" name="code"&gt;class Shiny_Validate_Omg extends Zend_Validate_Abstract {&lt;br /&gt;&lt;br /&gt;    const NOT_OMG = 'notOmg';&lt;br /&gt;&lt;br /&gt;    protected $_messageTempaltes = array(&lt;br /&gt;        self::NOT_OMG =&amp;gt; 'This is not omg'&lt;br /&gt;    );&lt;br /&gt;&lt;br /&gt;    public function isValid($value, $context = null) {&lt;br /&gt;        $value = (string)$value;&lt;br /&gt;        $this-&amp;gt;_setValue($value);&lt;br /&gt;        if (!isset($value) || 'omg' != strtolower($value) {&lt;br /&gt;            return false;&lt;br /&gt;        }&lt;br /&gt;        return true;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Your form class will look like this:&lt;br /&gt;&lt;br /&gt;&lt;pre class="php" name="code"&gt;class Application_Form_AddShiny extends Zend_Form {&lt;br /&gt;    public function init() {&lt;br /&gt;        // Here is the hard coded path I don't like&lt;br /&gt;        $this-&amp;gt;addElementPrefixPath('Shiny_', APPLICATION_PATH . '/shiny');&lt;br /&gt;        $this-&amp;gt;setMethod('post');&lt;br /&gt;&lt;br /&gt;        $this-&amp;gt;addElement('text', 'wtfisthis', array(&lt;br /&gt;            'filters' =&amp;gt; array('StringTrim'),&lt;br /&gt;            'validators' =&amp;gt; array(&lt;br /&gt;                array('Omg', false) // check if this is an OMG!!!!&lt;br /&gt;            )&lt;br /&gt;        ));&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So, who would have thought to call &lt;i&gt;addElementPrefixPath()&lt;/i&gt; to enable a custom validator? &amp;nbsp;Hopefully this is something that can be cleaned up for ZF2.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/11498321-7352917139199262241?l=weilandaj.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://weilandaj.blogspot.com/feeds/7352917139199262241/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=11498321&amp;postID=7352917139199262241' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11498321/posts/default/7352917139199262241'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11498321/posts/default/7352917139199262241'/><link rel='alternate' type='text/html' href='http://weilandaj.blogspot.com/2010/08/custom-form-validators-in-zend.html' title='Custom Form Validators in Zend Framework'/><author><name>Andrew</name><uri>http://www.blogger.com/profile/15797267658310961255</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-11498321.post-6930774928563768612</id><published>2010-03-19T10:34:00.000-04:00</published><updated>2010-03-19T10:34:01.261-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='jquery'/><category scheme='http://www.blogger.com/atom/ns#' term='prototype'/><category scheme='http://www.blogger.com/atom/ns#' term='webdev'/><title type='text'>Why I left Prototype for Jquery</title><content type='html'>&lt;b&gt;How I Found Prototype&lt;/b&gt;&lt;br /&gt;The reason I first stumbled on Prototype was because of &lt;a href="http://www.digg.com/"&gt;digg&lt;/a&gt;.&amp;nbsp; This is not the modern day digg that seems to enjoy lambasting Sarah Palin, but the prehistoric digg that was only tech news (the digg I miss that was slashdot++).&amp;nbsp; I discovered it while digging (no pun intended) through their page source.&amp;nbsp; I even "borrowed" one or two of their functions (Effect.FadeKeepSpace()) in my own digg clone that I wrote for &lt;a href="http://www.tribalwar.com/"&gt;TribalWar&lt;/a&gt;.&lt;b&gt;&amp;nbsp;&lt;/b&gt; &lt;br /&gt;&lt;br /&gt;Prototype was great.&amp;nbsp; It dealt with all of the cross-browser nonsense that made web development suck (mostly the fault of the engineers behind that abomination we call Internet Explorer).&amp;nbsp; I still remember the day that I gave up using &lt;i&gt;document.all&lt;/i&gt; for &lt;i&gt;document.getElementById()&lt;/i&gt;.&amp;nbsp; I relished in doing something the way it was supposed to be done.&lt;br /&gt;&lt;br /&gt;The joy of typing &lt;i&gt;$()&lt;/i&gt; over &lt;i&gt;document.getElementById() &lt;/i&gt;still exists to this day.&amp;nbsp; Short, sweet, and incredibly useful.&amp;nbsp; I will admit that I did not really understand the power of &lt;i&gt;$$()&lt;/i&gt; and css selectors until after my indoctrination to jquery but, it really does not matter in the grand scheme of things.&lt;br /&gt;&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Prototype Was Great&lt;/b&gt;&lt;br /&gt;As a modern student of computer science object oriented programming is king.&amp;nbsp; Prototype brought javascript into the object oriented mainstream like no other library (please excuse my ignorance of mootools here). &lt;br /&gt;&lt;br /&gt;Followed closely by the introduction of &lt;a href="http://scrtip.aculo.us/"&gt;scriptaculous,&lt;/a&gt; the web had a nice simple library to do some neat effects and simplify AJAX operations.&lt;br /&gt;&lt;br /&gt;With the object-orientedness of prototype combined with the super cool effects of prototype, the web really had a winner.&amp;nbsp; The only problem was over the years scriptaculous seemed to stagnate.&amp;nbsp; It doesn't seem like there's been much of an update in a long time (other than bug fixes).&amp;nbsp; I have a few &lt;a href="https://prototype.lighthouseapp.com/projects/8887/tickets/227-ajaxinplaceeditordispose-does-not-remove-title"&gt;bug reports&lt;/a&gt; of my own that haven't been dealt with in months.&amp;nbsp; Prototype seems to spend more time overhauling their docs recently than working on the library.&lt;br /&gt;&lt;br /&gt;However, the combination of the scriptaculous library with prototype is still impressive.&amp;nbsp; For a work project I extended the autocompleter to search within the first ajax search request as subsequent characters were typed by caching the results locally.&amp;nbsp; It made for fewer HTTP requests which should make &lt;a href="http://stevesouders.com/"&gt;Steve Souders&lt;/a&gt; happy.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;And Then There Was Jquery&lt;/b&gt;&lt;br /&gt;I kept hearing about this other library that seemed to be gaining quite a following.&amp;nbsp; After just a quick look over some sample code I dismissed it as messy and lacking simplicity.&amp;nbsp; I did not dig into it to quite understand how simple, yet powerful the library was.&amp;nbsp; After all, I was very happy with what I was already working with.&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;I took my first serious look at jquery when looking for what turns out to the the prototype equivalent of &lt;i&gt;$document.ready(...)&lt;/i&gt;.&amp;nbsp; It turns out it did not really exist (until recently that is as &lt;i&gt;document.observer('dom:loaded', ...)&lt;/i&gt;, but that did not help me at the time).&amp;nbsp; This piqued my interest enough to take a closer look at Jquery, and I'm glad that I did.&amp;nbsp; The syntax was shorter, quicker, more robust, and well documented with plenty of examples.&lt;br /&gt;&lt;br /&gt;To this day one of the best thing Jquery does is function chaining.&amp;nbsp; Having (almost) every function return the Jquery object is a brilliant yet simple philosophy.&lt;br /&gt;&lt;br /&gt;Instead of:&lt;br /&gt;&lt;pre class="js" name="code"&gt;me = $('findthis');&lt;br /&gt;me.doThis();&lt;br /&gt;me.doThat();&lt;br /&gt;me.andThat();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;It's all down to one line:&lt;br /&gt;&lt;pre class="js" name="code"&gt;$('#findthis).doThis().doThat().andThat();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Wonderful!&lt;br /&gt;&lt;br /&gt;Want to zebra stripe all of your tables?&lt;br /&gt;&lt;pre class="js" name="code"&gt;$('table tr:odd').css('background-color', '#aaaaa');&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Let's add a hover for the row:&lt;br /&gt;&lt;pre class="js" name="code"&gt;$(".stripeMe tr").mouseover(function() {&lt;br /&gt;    $(this).addClass("over");&lt;br /&gt;  }).mouseout(function() {&lt;br /&gt;    $(this).removeClass("over");&lt;br /&gt;  });&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Minified, Jquery weighs in at only 71k.&amp;nbsp; Scriptaculous and prototype don't even offer official minified versions so you either have to do it yourself or hope your server and browser support gzip (most should this day and age but it's usually up to the server admin to turn it on).&amp;nbsp; &lt;br /&gt;&lt;br /&gt;I could go on but I feel I've said my part.&amp;nbsp; I haven't even touched on plugins and the massive library available right on jquery.com (note to prototype/scriptaculous people, you need something like this badly.&amp;nbsp; I have found a few good repositories but nothing beats an official one).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;What I Miss About Prototype&lt;/b&gt;&lt;br /&gt;This discussion would not be complete without a lament for my former love.&amp;nbsp; I would like to take this opportunity to say that Prototype is not a bad framework.&amp;nbsp; In fact it is far from it.&amp;nbsp; It's just I find the way jquery does things overall to be better. &lt;br /&gt;&lt;br /&gt;I miss the object orientedness, specifically the ability to override functions but still being able to call parent the parent (like any good object oriented language).&amp;nbsp; Jquery it's a little more messy to do this; you have to save off a pointer to the old function yourself and call that.&amp;nbsp; Be nice and do it in a &lt;a href="http://www.bennadel.com/blog/1624-Ask-Ben-Overriding-Core-jQuery-Methods.htm"&gt;closure&lt;/a&gt; to not step on things.&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt; &lt;/b&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/11498321-6930774928563768612?l=weilandaj.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://weilandaj.blogspot.com/feeds/6930774928563768612/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=11498321&amp;postID=6930774928563768612' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11498321/posts/default/6930774928563768612'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11498321/posts/default/6930774928563768612'/><link rel='alternate' type='text/html' href='http://weilandaj.blogspot.com/2010/02/why-i-left-prototype-for-jquery.html' title='Why I left Prototype for Jquery'/><author><name>Andrew</name><uri>http://www.blogger.com/profile/15797267658310961255</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
