<?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>Adrian Schneider - Dev</title>
	<atom:link href="http://adrianschneider.ca/feed/" rel="self" type="application/rss+xml" />
	<link>http://adrianschneider.ca</link>
	<description>web application development, entrepreneurship, and life</description>
	<lastBuildDate>Mon, 16 Aug 2010 17:07:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Inline Zend Form Hints</title>
		<link>http://adrianschneider.ca/2010/08/inline-zend-form-hints/</link>
		<comments>http://adrianschneider.ca/2010/08/inline-zend-form-hints/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 16:56:09 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[zend_form]]></category>
		<category><![CDATA[zf]]></category>

		<guid isPermaLink="false">http://adrianschneider.ca/?p=337</guid>
		<description><![CDATA[One thing I always enjoy on sites is when they use the inline hints on text elements. Once you click on the element, the text disappears, and typically re-appears when it loses focus again, assuming it&#8217;s still empty.  Semantically, these have quite a different meaning than what a description is, so it&#8217;s nice to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/category/development/zend-framework/"><img class="alignright size-full wp-image-84" title="Zend Framework" src="/wp-content/uploads/2010/02/zend-framework.png" alt="" width="128" height="129" /></a>One thing I always enjoy on sites is when they use the inline hints on text elements. Once you click on the element, the text disappears, and typically re-appears when it loses focus again, assuming it&#8217;s still empty.  Semantically, these have quite a different meaning than what a description is, so it&#8217;s nice to also give users an example of the data, or an explanation of what you expect them to enter.  This is a huge help when you require certain formats of data (URLs, emails, dates, etc.)</p>
<p>I&#8217;ve been messing around with my base Zend_Form class and came up with a solid implementation now.  I&#8217;ve also expanded the concept to select elements, in which case it&#8217;d create a zero-value option with your hint.  This entire inline hint concept is enabled by JavaScript (in this case, jQuery), so when JavaScript is not enabled, nothing different will happen for users.  I think that&#8217;s ideal.<span id="more-337"></span></p>
<p><a href="http://adrianschneider.ca/wp-content/uploads/2010/08/hints.png"><img class="alignleft size-full wp-image-348" title="Hints Screenshot" src="http://adrianschneider.ca/wp-content/uploads/2010/08/hints.png" alt="" width="393" height="253" /></a>Here&#8217;s an example of what this is about.  For ideas, you&#8217;ll also notice that required fields are highlighted, and the hint is gray.  The hints for select menus are also gray, which makes it really easy to scan over forms, since the values you enter are black.</p>
<h3 style="clear:left">The Code</h3>
<pre><code>$a = new Zend_Form_Element_Text('email', array(
    'label'        =&gt; 'Your Email Address',
    'hint'         =&gt; 'name@site.com'
));

$b = new Zend_Form_Element_Select('category_id', array(
    'label'        =&gt; 'Category',
    'hint'         =&gt; 'Select a Category',
    'multiOptions' =&gt; $this-&gt;_getCategories()
));</code></pre>
<p>Here is the Form class code.  It takes the &#8216;hint&#8217; attribute we set in our form definitions, and adds a &#8216;placeholder&#8217; class, and sets the hint as the <em>rel</em> attribute.</p>
<pre><code>public function render(Zend_View_Interface $view = null) {
    $this-&gt;_applyHints();
    return parent::render($view);
}

public function _applyHints() {
    foreach ($this-&gt;getElements() as $element) {
        if ($element instanceof Zend_Form_Element_Text or
            $element instanceof Zend_Form_Element_Select or
            $element instanceof Zend_Form_Element_Textarea) {

            if ($hint = $element-&gt;hint) {
                $element-&gt;setAttrib('rel', $hint);
                $element-&gt;setAttrib('class', 'placeholder');
            }
        }

        if ($element-&gt;hint) {
            $element-&gt;setAttrib('hint', null);
        }
    }
}</code></pre>
<p>Here is the JavaScript (jQuery) code.</p>
<pre><code>$('.placeholder').each(function() {
    var item = $(this);

    // if hint
    if ($('#' + item.attr('id') + '-label label').hasClass('required')) {
        var text = item.attr('rel') + '    ';
    } else {
        var text = item.attr('rel');
    }

    var form = item.parents('form:first');

    // append option when hint is in place, and no 0 option exists
    if (item.is('select') &amp;&amp; item.find('option[value=0]').length == 0) {
        item.html('&lt;option value="0"&gt;' + text + '&lt;/option&gt;' + item.html());
        item.change(function() {
            if ($(this).val() == 0) {
                $(this).css('color', '#ddd');
                $(this).find('option[value!=0]').css('color', '#000');
            } else {
                $(this).css('color', '#000');
                $(this).find('option[value=0]').css('color', '#ddd');
            }
            return true;
        });
        item.change();
    }

    if (item.val() === '') {
        item.val(text);
        item.css('color', '#ddd');
        item.data('hint', text);
    }

    item.bind('focus.placeholder', function(event) {
        if (item.val() == text) {
            item.css('color', '#000').val('');
        }
    });

    item.bind('blur.placeholder', function(event) {
        if (item.val() === '') {
            item.css('color', '#ddd').val(text);
        }
    });

    form.bind('submit.placeholder', function(event) {
        if (item.val() === text) {
            item.css('color', '#000').val('');
        }

        if (item.is('select')) {
                var val = item.val();
                if (item.attr('rel') == item.find('option[value=' + val + ']').text()) {
                    item.find('option[value=0]').remove();
                }
        }
    });
});</code></pre>
<p>There are a few things to note here&#8230; on basic text fields, if the element is required, I append whitespace to the stored hint, which allows us to detect when they enter text that matches the (visible) hint.  For example, if it&#8217;s a name element, and the hint is &#8216;John&#8217;, that is surely an allowed option.  However, if it&#8217;s not required, then the the user cannot enter something that matches the hint, so be sure to use formatting examples (ex: &#8216;m-d-Y&#8217; instead of a real date).</p>
<p>On select elements, the hints only really make sense (to me) for required fields where the hint is a 0-value option similar to  &#8220;Select a Category&#8221;.  To prevent the standard 0 not found in the haystack error presented when the user skips the field, you should set the &#8216;errorMessages&#8217; option on the element to something like &#8216;Please select a valid category&#8217;, as that&#8217;s really the only valid error condition that can happen.</p>
<h3>Just a Concept</h3>
<p>I&#8217;m currently only using this in an admin area for testing, but it seems to work really well so far.  We&#8217;ve had a lot of positive feedback about it, and being able to use these sort of features application-wide saves the chore of having to un-do it later or add it to 1000 files.  If you have some suggestions on improvements to this be sure to post in the comments.  It&#8217;d be nice to have it valid HTML (rel attribute) for all the purists as well.  Hope this helps someone!</p>
<p>Cheers</p>
]]></content:encoded>
			<wfw:commentRss>http://adrianschneider.ca/2010/08/inline-zend-form-hints/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Meet Upscale International</title>
		<link>http://adrianschneider.ca/2010/08/meet-upscale-international/</link>
		<comments>http://adrianschneider.ca/2010/08/meet-upscale-international/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 08:06:46 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Upscale]]></category>
		<category><![CDATA[siradrian]]></category>
		<category><![CDATA[upscale international]]></category>

		<guid isPermaLink="false">http://adrianschneider.ca/?p=314</guid>
		<description><![CDATA[Freelancing has been tough for me this past year.  Money has been tight, and the stresses of dealing with clients and family was becoming overwhelming.  If I was to sustain my mental sanity I needed some drastic changes.  After a while of various online gigs flopping, I decided to look locally.  [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://upscaleinternational.com/"><img src="http://adrianschneider.ca/wp-content/uploads/2010/08/Blue_Gradient_Logo-e1281516764604-150x150.jpg" alt="Upscale International" title="Upscale International" width="128" class="alignright size-thumbnail wp-image-326" /></a>Freelancing has been tough for me this past year.  Money has been tight, and the stresses of dealing with clients and family was becoming overwhelming.  If I was to sustain my mental sanity I needed some drastic changes.  After a while of various online gigs flopping, I decided to look locally.  I talked to a few companies, but the salary difference between the work I was doing online and what I&#8217;d be doing locally was ridiculous.  I met some really cool people though, so I have no regrets about the whole process. I can get more into another day.  <span id="more-314"></span></p>
<p>Unfortunately, people rarely need to hire lead or senior programmers, at least where I live.  This was becoming evident.  The only next logical choice I could think of was to move out of the home office and try to do things a bit more seriously.  I ended up moving into a friend of mine&#8217;s temporary office with their team.  We went to school together throughout elementary, middle and high school, and roomed together for several months about a year after school.   They ran a web firm with some very interesting connections and projects.   Unfortunately, it seemed like their company was falling apart with the efforts looking like a reversed triangle.  After a month or two, it toppled, leaving everything in shambles.  With the old leader / programmer out of the way, we were left with quite an interesting team: a developer, a network security/all-around geek, a manager, and a salesman.</p>
<p>After this had happened, it dawned on me that a start-up was exactly what I was looking for.  For some reason, as a developer, a lot of the clients I&#8217;ve dealt with didn&#8217;t give a shit about my input on some of the applications they had planned.  Or worse: they assumed that because I was a developer, I didn&#8217;t know anything about it.   It was hell having to sacrifice good architecture for crap to make unrealistic deadlines or budgets. As the technical leader of a start-up, I get complete creative control on projects and don&#8217;t have to make sacrifices.  If I do, they are realistic ones that everyone can be involved in deciding.</p>
<p>Since the new company has formed, we have been working on a lot of the usual client work from both their old company, and my &#8220;SirAdrian&#8221; business.  It&#8217;s been a huge transition, but we are almost done now.  The client work is purely transitional (ideally).  About 20% of my time has also been working on our first product.  As a service, we are always trading time for money, and have a very limited reach.  As a product company, we can create value once, and sell it to the masses.  Our real focus is going to be targeting the Health care industry.  Our CEO is still heavily involved in health, with over 25 years of relationships and experience.  Perfect combination.</p>
<p>We are about 3 months in, and have moved into a local tech incubator called ORIC which has been an enormous help in the start-up phase.  The networking here alone has been worth it already, but we will also be doing team mentoring sessions and attending events they put on.  All in our building.  Our first product is planned to launch September 1st, so this is going to be one hell of a ride.</p>
]]></content:encoded>
			<wfw:commentRss>http://adrianschneider.ca/2010/08/meet-upscale-international/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework Models &#8211; Part 1: Concepts</title>
		<link>http://adrianschneider.ca/2010/02/zend-framework-models-part-1-concepts/</link>
		<comments>http://adrianschneider.ca/2010/02/zend-framework-models-part-1-concepts/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 09:40:38 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[zend_db]]></category>
		<category><![CDATA[zend_db_select]]></category>
		<category><![CDATA[zf]]></category>

		<guid isPermaLink="false">http://www.siradrian.com/blog/?p=257</guid>
		<description><![CDATA[The power in Zend Framework lies in its uncompromising flexibility.  However, evidently, this also means its very difficult for new ZF users to pick up the framework and hit the ground running.  The most common question I see is usually &#8220;where is the model?&#8221;.  The goal of this post is to show [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/category/development/zend-framework/"><img class="alignright size-full wp-image-84" title="Zend Framework" src="/wp-content/uploads/2010/02/zend-framework.png" alt="" width="128" height="129" /></a>The power in Zend Framework lies in its uncompromising flexibility.  However, evidently, this also means its very difficult for new ZF users to pick up the framework and hit the ground running.  The most common question I see is usually &#8220;where is the model?&#8221;.  The goal of this post is to show some examples and hopefully some new ideas on how to tackle models.  There is no one-size-fits-all solution folks.  Let&#8217;s look at some options and some background&#8230;<span id="more-257"></span></p>
<p><strong>The concept of a model</strong></p>
<p>Before we can go any further, we must first figure out what a model is.  This stuff isn&#8217;t an exact science, so there will be some gray areas.  Much of this post is my opinion (read: not fact).  This doesn&#8217;t necessarily make them right or wrong.   I like to think I&#8217;m right, so feel free to argue with me in the comments below.  </p>
<p>In an MVC application, the model is responsible for all the business logic. The controller should handle flow control (taking input, calling models, redirection, etc.), and the view is responsible for representing your application, usually with some sort of data language (XML, HTML, JSON, etc.)</p>
<p><a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller"><img class="aligncenter" title="MVC" src="http://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/ModelViewControllerDiagram.svg/350px-ModelViewControllerDiagram.svg.png" alt="" width="350" height="165" /></a></p>
<p>Implementation and and interpretation of the pattern is up to the developer&#8230; there are some gray areas so don&#8217;t worry if it doesn&#8217;t meet the exact specification.  However, one thing I like to practice is <em>skinny controllers, fat models</em>.  By shifting a lot of the work to the models (and their underlying libraries) you can usually organize your application much better.  The result is simpler and more organized (primarily better encapsulated) code.</p>
<p>Simply said, a model should contain your business logic.  Any processing that revolves around your application data should probably be put into models.  I consider a model to be anything that does something in the big picture of your application&#8230; things like reading/writing data, sending/receiving data, processing data.  They do the &#8220;work&#8221;.</p>
<p>One mistake I see is people simply setting up ORM (ex: Doctrine) models for each of their tables and leaving it at that.  Your models&#8217; public interfaces should be very simple. I prefer to have their interface represent their actual domain logic.  For example, if you are making a post, then your controller (or calling code) should simply call something very self explanatory like post-&gt;create( info ).  One personal guideline I follow is not to have more than 4 or 5 parameters to a method, and ideally, only 1 to 3.</p>
<p>One common implementation of this annoyance of mine is putting in chained query calls in your controller.  Yes, the actual database code is encapsulated, but you are still revealing way too much information in your controller.  The whole point of them is to encapsulate not only the code, but also the underlying logic.  This way, when your business logic changes, your controllers can usually continue to function properly.  </p>
<p><strong>Working with databases</strong></p>
<p>Most web applications revolve around storing information in the database.  Whether it&#8217;s posts, comments or pictures, it all boils down to the same few operations.  You can call this CRUD: create, read, update and destroy.  In practice, it&#8217;s often much more complicated&#8230; but they remain to be the underlying concepts for most database interaction.</p>
<p>Most other frameworks come with a default model class/component which is a huge push in the right direction.  Zend keeps an open mind about it, providing a few tools to use if you want to work with the database.  Zend comes with a huge Zend_Db component to handle your database operations.  It also contains Zend_Db_Table which is an implementation of the Table Data Gateway and Row Data Gateway patterns.</p>
<p>Personally, I&#8217;m not a big fan of Zend_Db_Table.  I still think Doctrine is much more powerful, though I do really like Zend_Db.  It operates under some of the same principles as PDO (database abstraction layer), so if you have used that before, you will be at home.   I also really like Zend_Db_Select, which is what the table classes use quite a bit.</p>
<p><strong>Using a base model</strong></p>
<p>Because there are so many different types of models, I don&#8217;t think there is much point in having a do-it-all base class.  However, for the group of models that will need database access, I use something like this:</p>
<pre><code>class Site_Model {
    protected $_db;

    public function __construct(Zend_Db_Adapter_Abstract $db) {
        $this-&gt;_db = $db;
    }
}</code></pre>
<p>You can probably tell that the default model is not even needed&#8230; and that&#8217;s the point.  However, depending on your needs, this is a good place to start adding some common functionality that your db models will need.  You may want to also make them all loader or dependency injector friendly if your application requires that.</p>
<p><strong>Zend_Db</strong></p>
<p>Zend&#8217;s database abstraction layer is really nice to work with.  If you use it in combination with Zend_Db_Select you can make the database end of your application very portable.  Here are some common methods I use from Zend_Db:</p>
<pre>query(string)

fetchOne(query)
fetchRow(query)
fetchAll(query)

insert(table, data)
update(table, data, where)
delete(table, where)

quote(value)
quoteInto(string, value)</pre>
<p><strong>Abstracting your queries</strong></p>
<p>If I&#8217;m working on an application that I plan to release to the public, then I always use Zend_Db_Select.  It works on the same concept as the above insert/update/delete methods, meaning that you never have to write any of the SQL.  If you let the Db libraries do it, then you are able to get much more portable code.  Zend_Db supports IBM&#8217;s DB2, MySQL, MSSQL, Oracle, PostgreSQL and SQLite, so Db_Select is targetted at the same databases.</p>
<p>The concept of Zend_Db_Select is that the query is an object, and you can add/modify different parts of it.  This gives you a lot more flexibility over dynamic query creation, as well as the added bonus of portability.  </p>
<p><strong>Summary</strong></p>
<p>For your basic database-oriented models, all you your class will need is access to the Zend_Db_Adapter_Abstract interface.  Keep your public methods very domain-oriented and your controllers will thank you for it.  Break out of the mindset that models = database tables, or even model = database.  Usually only around half my models deal with database operations.   ZF also has a ton of service libraries available to help with all the common social sites APIs out there.  </p>
<p>The next installment of this post will go into some concrete examples and also some ideas on how to implement your models.   Comments and criticism welcomed and appreciated as always. <img src='http://adrianschneider.ca/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://adrianschneider.ca/2010/02/zend-framework-models-part-1-concepts/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Testing Zend_Mail</title>
		<link>http://adrianschneider.ca/2010/02/testing-zend_mail/</link>
		<comments>http://adrianschneider.ca/2010/02/testing-zend_mail/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 19:49:17 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sendmail]]></category>
		<category><![CDATA[zend_mail]]></category>
		<category><![CDATA[zf]]></category>

		<guid isPermaLink="false">http://www.siradrian.com/blog/?p=221</guid>
		<description><![CDATA[Since I work on a local development machine/server, I&#8217;ve never taken the time to set up mail yet, nor do I want to.  I think a staging environment is more appropriate to actually have email being sent out.  Nevertheless, it has made testing any email functionality a little cumbersome.  I&#8217;ve done a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://adrianschneider.ca/category/development/zend-framework/"><img src="http://adrianschneider.ca/wp-content/uploads/2010/02/zend-framework.png" alt="" title="Zend Framework" width="128" height="129" class="alignright size-full wp-image-84" /></a>Since I work on a local development machine/server, I&#8217;ve never taken the time to set up mail yet, nor do I want to.  I think a staging environment is more appropriate to actually have email being sent out.  Nevertheless, it has made testing any email functionality a little cumbersome.  I&#8217;ve done a little research, and have found two ways to tackle the problem.  I&#8217;ve also included code samples and other resources to get you started.  <span id="more-221"></span></p>
<p><strong>Create a new mail transport class</strong></p>
<p>Zend has the ability to set a default mail transport class to be used when none is specified, which I&#8217;d imagine to be 99% of the time.  To set it, all you need to do is put this somewhere early in your application before any mail code is executed.  </p>
<pre><code>Zend_Mail::setDefaultTransport(new Site_Mail_Transport_Debug());</code></pre>
<p>The alternative (for the 1% who want to manually specify), you&#8217;d simply pass an instance of your mail transport object to Zend_Mail::send() when you call it.  What should your class contain?  It has to extend Zend_Mail_Transport_Abstract, which at this time of writing this, will specifically need to override the abstract _sendMail() method.</p>
<p>You can use it to create a new record in your database, create a file, or do whatever you need it to.  I quickly hacked together one to log it to the database, and based it off of the Sendmail transporter, which is pretty much a wrapper for PHP&#8217;s mail function.  Here is the code I came up with for those who want some direction.  It&#8217;s very basic, but should be enough to get you started.</p>
<pre><code>&lt;?php

class Site_Mail_Transport_Debug extends Zend_Mail_Transport_Abstract {

    public function __construct(Zend_Db_Adapter_Abstract $db) {
        $this-&gt;_db = $db;
    }

    public function _sendMail() {
        $this-&gt;_db-&gt;insert(
            'mailtest',
            array(
                'recipients' =&gt; $this->recipients,
                'subject'    =&gt; $this->_mail->getSubject(),
                'body'       =&gt; $this->body,
                'header'     =&gt; $this->header
            )
        );
    }
}</code></pre>
<p><strong>Override it at the server level</strong></p>
<p>This is a good idea if you don&#8217;t use Zend Framework, or don&#8217;t use it for all of your applications.  There are two great techniques described on <a href="http://akrabat.com/php/redirecting-email-whilst-developing/">akrabat&#8217;s blog</a>.  Here they are.</p>
<p>The first, is to override php.ini&#8217;s &#8217;sendmail_path&#8217; and create your own script to handle it.  If you were to set it to
<pre><code>sendmail_path = /usr/local/bin/trapmail</code></pre>
<p> then you&#8217;d use the following code
<pre><code>formail -R cc X-original-cc
  -R to X-original-to
  -R bcc X-original-bcc
  -f -A"To: your@emailaddress.com"
| /usr/sbin/sendmail -t -i</code></pre>
<p>This requires you to have mail configured on your server, but it still solves the underlying problem of wanting to debug the emails, and also not send out test emails to real users in your application.</p>
<p>The second solution provided is platform independent <strike>is for Windows users</strike>, and it&#8217;s to install  <a href="http://www.lastcraft.com/fakemail.php">fakemail</a>.  This program acts as an outgoing mail server, but instead creates files containing any mail passed to it.</p>
<p>Hopefully this helps others out who are also frustrated with dealing with pesky email debugging.  </p>
]]></content:encoded>
			<wfw:commentRss>http://adrianschneider.ca/2010/02/testing-zend_mail/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Caching Zend Framework Forms</title>
		<link>http://adrianschneider.ca/2010/02/caching-zend-framework-forms/</link>
		<comments>http://adrianschneider.ca/2010/02/caching-zend-framework-forms/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 22:24:33 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[zend_form]]></category>
		<category><![CDATA[zf]]></category>

		<guid isPermaLink="false">http://www.siradrian.com/blog/?p=164</guid>
		<description><![CDATA[Generating a form is an expensive process in ZF.  It&#8217;s always bugged me that I can&#8217;t find any resources on trying to cache the initial HTML anywhere, so I took a stab at it myself.  I use a loader from inside my controller action to load forms and models, so I found that [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/category/development/zend-framework/"><img src="/wp-content/uploads/2010/02/zend-framework.png" alt="" title="Zend Framework" width="128" height="129" class="alignright size-full wp-image-84" /></a>Generating a form is an expensive process in ZF.  It&#8217;s always bugged me that I can&#8217;t find any resources on trying to cache the initial HTML anywhere, so I took a stab at it myself.  I use a loader from inside my controller action to load forms and models, so I found that was a good place to start.</p>
<p>Here is my initial loader class, which I have stripped down and simplified for the sake of this example.  Ideally, you&#8217;d want this in something like an action helper.<span id="more-164"></span></p>
<pre><code>&lt;?php

class Site_Loader {
    /**
     * Site's controller action
     * @var        Site_Controller_Action
     */
    protected $_controllerAction;

    /**
     * Sets the current controller action we're being called from
     * @param       Site_Controller_Action
     */
    public function setControllerAction(Site_Controller_Action $action) {
        $this-&gt;_controllerAction = $action;
    }

    /**
     * Loads the requested form class
     * Same conventions as Zend (Form_Name = Form/Name.php) class "Form_" . $Form_Name
     *
     * @param    string        The name of the form class
     * @param    string        Any options for the form class constructor
     * @return   object        Form class object - forms_$formName
     */
    public function form($formName, $options = null) {
        $path = APP_DIR . "/application/forms/" . str_replace('_', '/', $formName) . '.php';
        require_once $path;

        $class = "Form_" . $formName;
        return new $class($this-&gt;_controllerAction, $options);
    }
}</code></pre>
<p>I always find it useful to have access to the controller in forms &#8211; especially to access the request information.  Another reason is we can use it to determine the request method &#8211; more importantly, see if it&#8217;s POST.   When it&#8217;s not, then we can enable caching, because the form output should not change.  Only when they actually post something should we need to show anything different.  I set a high cache TTL simply because I&#8217;d want it to be there forever, until I actually modify the form code, at which point I&#8217;d clear its cache.  With that in mind, here is the updated (and relevant parts of)  the loader.</p>
<pre class="highlightcode"><code>&lt;?php

class Site_Loader {
    /**
     * Site's controller action
     * @var        Site_Controller_Action
     */
    protected $_controllerAction;
<strong>
    /**
     * Caching object used
     * @var         Zend_Cache_Core
     */
    protected $_cache;</strong>

    /**
     * Sets the current controller action we're being called from
     * @param       Site_Controller_Action
     */
    public function setControllerAction(Site_Controller_Action $action) {
        $this-&gt;_controllerAction = $action;
    }
    <strong>
    /**
     * Sets the cache object to be used
     * @param       Zend_Cache_Core
     */
    public function setCache(Zend_Cache_Core $cache) {
        $this-&gt;_cache = $cache;
    }</strong>

    /**
     * Loads the requested form class
     * Same conventions as Zend (Form_Name = Form/Name.php) class "Form_" . $Form_Name
     *
     * @param    string        The name of the form class
     * @param    string        Any options for the form class constructor
     * @return   object        Form class object - forms_$formName
     */
    public function form($formName, $options = null) {
        $path = APP_DIR . "/application/forms/" . str_replace('_', '/', $formName) . '.php';
        require_once $path;

        $class = "Form_" . $formName;
        return new $class($this-&gt;_controllerAction, $options);
    }
    <strong>
    /**
     * Loads the requested form class.
     * When request method is post, form is loaded normally.
     * When it's not, cache is used to reduce CPU load.
     *
     * @param   string      The name of the form class
     * @param   string      Any options for the form class constructor
     *
     * @return  mixed       Form class object, or rendered form HTML when caching is active
     */
    public function formCached($formName, $options = null) {
       if ($this-&gt;_controllerAction-&gt;getRequest()-&gt;isPost()) {
           return $this-&gt;form($formName, $options);
       }

       if ($out = $this-&gt;_cache-&gt;load($id = $this-&gt;_getFormCacheId($formName, $options))) {
           return $out;
       }

       $form = $this-&gt;form($formName, $options);
       $this-&gt;_cache-&gt;save($out = $form-&gt;__toString(), $id, array(), 31536000);

       return $out;
    }

    /**
     * Generates the id used for the cache.  It must be unique for the name of the
     * form, and the options passed to it.
     *
     * @param   string      Form name used
     * @param   mixed       Array of options passed to form, or null
     *
     * @return  string      Unique ID for this form cache
     */
    protected function _getFormCacheId($formName, $options = null) {
       if ($options === null) {
           return "Form_$formName";
       }

       return 'Form_' . $formName . md5(serialize($options));
    }</strong>
}</code></pre>
<p><strong>Enabling Caching</strong></p>
<p>This is generally how a basic form action looks like in my controllers.
<pre>public function postAction() {
    $form = $this-&gt;loader-&gt;form('Post_Create', $options = array());

    if ($this-&gt;_request-&gt;isPost()) {
        if ($form-&gt;isValid($this-&gt;_request-&gt;getPost())) {
            $post = $this-&gt;model-&gt;create($form-&gt;getValues());
            $this-&gt;redirector-&gt;goToUrl($post-&gt;getUrl());
        }
    }

    $this-&gt;view-&gt;form = $form;
}</code></pre>
<p>With it enabled, we&#8217;d simply change
<pre>$this-&gt;loader-&gt;form()</pre>
<p> to
<pre>$this-&gt;loader-&gt;formCached()</pre>
<p>  Since the only interaction with my form and view script is
<pre>&lt;?= $this-&gt;form ?&gt;</pre>
<p> we don&#8217;t even have to change it.  The form&#8217;s __toString method will work normally when the caching isn&#8217;t active, and the form variable is just a string when it is.  Simple.</p>
<p><strong>Recap</strong></p>
<p>This will allow for the caching of your rendered ZF forms.  It is disabled automatically when the request method is POST, so it can properly re-populate your data and/or show your errors.  If you use the simple form renderings in your view scripts, then they will work as-is.  This is all just a proof of concept that I am testing on a few sites at the moment.  If you have any feedback or questions, don&#8217;t hesitate to let me know.  </p>
]]></content:encoded>
			<wfw:commentRss>http://adrianschneider.ca/2010/02/caching-zend-framework-forms/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Quick mysql_insert_id() Tip</title>
		<link>http://adrianschneider.ca/2010/02/quick-mysql_insert_id-tip/</link>
		<comments>http://adrianschneider.ca/2010/02/quick-mysql_insert_id-tip/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 23:38:08 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.siradrian.com/blog/?p=157</guid>
		<description><![CDATA[If you are working with multiple connections, you must specify the connection to mysql_insert_id().  Unlike other functions, it does not attempt to use the last opened connection, but instead fails returning false.  Hopefully this helps someone else is as confused as I was last night.  
]]></description>
			<content:encoded><![CDATA[<p><a href="/tag/mysql/"><img src="/wp-content/uploads/2010/02/logoMysql.png" alt="" title="MySQL" width="128" height="78" class="alignright size-full wp-image-161" /></a>If you are working with multiple connections, you must specify the connection to mysql_insert_id().  Unlike other functions, it does not attempt to use the last opened connection, but instead fails returning false.  Hopefully this helps someone else is as confused as I was last night.  </p>
]]></content:encoded>
			<wfw:commentRss>http://adrianschneider.ca/2010/02/quick-mysql_insert_id-tip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Forms in Zend Framework</title>
		<link>http://adrianschneider.ca/2010/02/forms-in-zend-framework/</link>
		<comments>http://adrianschneider.ca/2010/02/forms-in-zend-framework/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 08:40:45 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[zend_form]]></category>
		<category><![CDATA[zf]]></category>

		<guid isPermaLink="false">http://www.siradrian.com/blog/?p=119</guid>
		<description><![CDATA[I&#8217;m often asked what my favorite component of Zend Framework is, and I invariably answer: &#8220;Forms&#8221;.   Forms have always played an awkward role in the model-view-controller paradigm.  Sure, the form is just HTML, but to me, it represents something more abstract than that.  It represents the HTML form itself, taking user [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/category/development/zend-framework/"><img src="/wp-content/uploads/2010/02/zend-framework.png" alt="" title="Zend Framework" width="128" height="129" class="alignright size-full wp-image-84" /></a>I&#8217;m often asked what my favorite component of Zend Framework is, and I invariably answer: &#8220;Forms&#8221;.   Forms have always played an awkward role in the model-view-controller paradigm.  Sure, the form is just HTML, but to me, it represents something more abstract than that.  It represents the HTML form itself, taking user input, normalizing and validating it, and also being able to show the form again when errors occur.  This can take quite a large amount of code.<span id="more-119"></span></p>
<p>If you&#8217;re able to automate all of that stuff, then all you are really left with is configuration.  Each form consists of elements, and each element has several attributes which modify the overall functionality of the form.  Let&#8217;s look at some of these aspects. </p>
<p><strong>Defining a Form</strong></p>
<p>A form itself is an instance of Zend_Form.  There are many ways to define one.  I prefer to extend Zend_Form for each of my forms, and define them inside the class itself.  Each form contains a few important fields (action, method) and also it contains at least one element.  Let&#8217;s look at how we define an element.  Each element probably has a few common attributes: a field type, a label, an element name, and a description.  Let&#8217;s represent this element in ZF. Note, there are several different ways to represent forms.  They can literally be done via configuration, or by a few different PHP methods.  This is my favorite.</p>
<pre><code>$username = new Zend_Form_Element_Text('username', array(
    'label'         =&gt; 'Username',
    'description'   =&gt; 'This is a description'
));</code></pre>
<p>In the above code, you can see we define these three things.  There are also some other important attributes for elements.  Let&#8217;s add a few more, and show a few fields at once.  </p>
<pre><code>$this->addElements(array(
    new Zend_Form_Element_Text('username', array(
        'label' => 'Username',
        'required' => true
    )),
));</code></pre>
<p><strong>Filters and Validators</strong></p>
<p>One very helpful feature with the forms component is the ability to chain filters and validators.  A filter is something that automatically manipulates incoming data to your desired format, and a validator is something that is checked when processing the form.   This greatly simplifies your controller code, and your model code, because you are shifting all of this logic into a much more organized structure.</p>
<p>For example,  if you are working with a username element on a registration form, then you may want check that the user does not already exist, the username does not contain any illegal characters, and the username is within a desired length.  </p>
<p>If you had an element where the user can enter a few paragraphs about himself, then you would want to apply some filters to make sure the data is clean.  You may want to add things like StripTags to remove any HTML, StringTrim to remove any extra whitespace, etc.   You could also apply some custom BBCode parsing filters if you wanted.  You could create your own filter for this, or use the Callback filter which you can use for everything else.</p>
<p>The idea is to do as much validation as possible so you know that your data is 100% ready for your application.  If you have a VARCHAR(255) field, then limit your string to 255 characters so nothing gets truncated.    Be very strict.</p>
<p>Filters are more of a time saver to me&#8230; but they are nice because they help keep all the data very consistent or can also be part of your cleaning process. If you are allowing user input, then remove any HTML is necessary.  You get the idea.</p>
<p>Here is a more complete example of a registration form definition:</p>
<pre><code>$this-&gt;addElements(array(
    new Zend_Form_Element_Text('username', array(
        'label'        =&gt; 'Username',
        'required'     =&gt; true,
        'validators'   =&gt; array(
            array('StringLength',      false, array(4, 16)),
            array('Alnum'),
            array('Db_NoRecordExists', false, array('users', 'username'))
        )
    )),
    new Zend_Form_Element_Text('email', array(
        'label'        =&gt; 'Email Address',
        'required'     =&gt; true,
        'validators'   =&gt; array(
            array('EmailAddress'),
            array('Db_NoRecordExists', false, array('users', 'email'))
        )
    )),
    new Zend_Form_Element_Password('password', array(
        'label'        =&gt; 'Password',
        'required'     =&gt; true
    ))
));</code></pre>
<p><strong>Skinny Controller, Fat Model</strong></p>
<p>With a form containing the fields above, we can really simplify our controller code.  To me, controller&#8217;s should contain the flow of an application, without really performing any of the work.  Here is an example of a registration action.</p>
<pre><code>if ($this->_request->isPost()) {
    if ($form->isValid($this->_request->getPost())) {
        $user->register($form->getValues());
        $this->redirector->goToUrl('/welcome');
    }
}

$this->view->form = $form;</code></pre>
<p>If the user has submitted (posted) any information, then the form validates that posted information.  If it&#8217;s valid, it will proceed to pass the data array to our model.  At this point, all of our filters and validators have been executed, so we know exactly how the data is formatted, and that it&#8217;s safe to use.  We can proceed to redirect the user away, or perform any other flow logic we need to at this point.</p>
<p>We also pass the form to the view, which is crucial.  On a regular page view, the form will be loaded normally.   On a failed submission, then it will show the form with all of the error messages, and the posted data populated back into the form elements.  </p>
<p><strong>View Scripts &amp; Decorators</strong></p>
<p>Here is all the code we need in our view to show a form.  The rest can be done via CSS, or custom decorators if we need it. </p>
<pre><code>&lt;?= $this-&gt;form ?&gt;</code></pre>
<p>By default, Zend_Form outputs a pretty usable chunk of HTML.  I have no problems styling it via CSS which is really great for our separation of concerns.  However, there will be times when you need markup in certain format, and Zend can handle this with decorators.  They are a little tricky to learn, so I will save that for another blog post.  There should be sufficient documentation on their website.</p>
<p><strong>Dealing with Models</strong></p>
<p>As per our controller code, the model would receive $form->getValues(), which would be a pre-validated and pre-filtered array of our data.  Here is an example:</p>
<pre><code>// ...
public function register(array $user) {

}
// ...</code></pre>
<p>To me, this is beautiful.  We are working with a very basic interface, and do not have to manually specify every value that we pass or expect.  While this is personal taste, I cringe whenever I see people pass 5-10 values to a model.  Their controllers all end up being huge.  The code is also not dependent on our form, because it&#8217;s just dealing with an array of data.  It makes <em>calling</em> our models very simple, too.  The model is where the code should start to get complicated.  From this point, we can use our database adapter object, or deal with several other libraries.</p>
<p><strong>Summary</strong></p>
<p>The form component is one of the larger (largest?) components in Zend.  Don&#8217;t be afraid to ask for help on the different forums, or ask below and I can point you to a good resource.  Like I said above, this is the most useful component in Zend to me, so if you are considering taking the time to learn how to use it, I strongly advise to do so.</p>
<p>You may also be interested in <a href="/2010/02/caching-zend-framework-forms/">caching forms</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://adrianschneider.ca/2010/02/forms-in-zend-framework/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Picking a Framework</title>
		<link>http://adrianschneider.ca/2010/02/picking-a-framework/</link>
		<comments>http://adrianschneider.ca/2010/02/picking-a-framework/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 06:43:20 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[code igniter]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[zf]]></category>

		<guid isPermaLink="false">http://www.siradrian.com/blog/?p=48</guid>
		<description><![CDATA[Over the past few years I have checked out many of the popular PHP frameworks out there.  The three I did the most development with were CakePHP, CodeIgniter and Zend Framework.  Each one has fills a very different set of needs, and I think most people do not understand that.  People seem [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-86" title="PHP" src="/wp-content/uploads/2010/02/php.png" alt="" width="128" height="84" />Over the past few years I have checked out many of the popular PHP frameworks out there.  The three I did the most development with were CakePHP, CodeIgniter and Zend Framework.  Each one has fills a very different set of needs, and I think most people do not understand that.  People seem to take framework reviews very personally for some reason as if its a reflection of their ability.</p>
<p><strong>Addressing Your Needs</strong></p>
<p>To oversimplify things, it&#8217;s easy to map your role with some of the different frameworks.  I choose these three, because they represent my point very well.  I&#8217;m going to fudge the definitions a little bit here, and toss WordPress (or &#8216;insert your favorite CMS here&#8217;) into the mix as well.  While the mapping may be an oversimplification, remember that the particular role&#8217;s core needs may match your needs for a project, even if you fit another role.<span id="more-48"></span></p>
<p><strong>Designers &amp; Writers &#8211; WordPress</strong></p>
<p><a href="http://wordpress.com/"><img class="alignright size-full wp-image-80" title="WordPress" src="/wp-content/uploads/2010/02/wordpress-logo1.jpg" alt="" width="128" height="127" /></a>If you are a designer or content writer, you will want something simple to use like WordPress.  It&#8217;s pretty easy to skin, and there is a wide variety of plugins/themes available.  Even these add-ons are easy to work with.  Given the short time required to get started, this is the most common choice for new websites, at least from what I have seen.  Even web development firms will choose this when it fits the bill.  There is no shame in that.</p>
<p>Keep in mind though, the WordPress codebase may not be the most flexible, and that is usually when you start climbing the ladder to more advanced solutions.</p>
<div class="proscons">
<div class="cons">
<p><strong>Cons:</strong></p>
<ul>
<li>Lower code quality</li>
<li>Hard to modify functionality</li>
</ul>
</div>
<div class="pros">
<p><strong>Pros:</strong></p>
<ul>
<li>Huge community</li>
<li>Quick to launch sites</li>
<li>Simple interface</li>
<li>Great plugins and themes</li>
</ul>
</div>
</div>
<p><strong>Coders and Designers &#8211; CakePHP</strong></p>
<p><a href="http://cakephp.org/"><img class="alignright size-full wp-image-82" title="CakePHP" src="/wp-content/uploads/2010/02/cakephp.png" alt="" width="128" height="120" /></a>If you want a framework gets you from zero to launch very quickly, then look no further than CakePHP.  It&#8217;s an MVC based framework, like the others, and imposes very strict coding conventions.  This means if you learn how to code the &#8216;CakePHP way&#8217;, then it will do a lot of the work for you.  Sounds too good to be true?  It is, sometimes.  Once you begin to deviate from the way CakePHP does things, then it becomes very frustrating to work with.  However, its primary target audience is people who want to get applications up and running very fast.  If I remember correctly, it&#8217;s based on some of the concepts of Ruby on Rails.</p>
<p>One thing Cake does very well is creating &#8220;CRUD&#8221; applications.  CRUD stands for CREATE, READ, UPDATE, DELETE.  These are common operations for custom (but relatively simple) databases.  The work I have done with this was actually a pleasure, though pretty slow.</p>
<div class="proscons">
<div class="cons">
<p><strong>Cons</strong></p>
<ul>
<li>Forced conventions</li>
<li>Slower codebase</li>
<li>Outdated codebase (PHP 4)</li>
<li>Deep inheritences</li>
</ul>
</div>
<div class="pros">
<p><strong>Pros:</strong></p>
<ul>
<li>Shorter learning curve</li>
<li>Rapid development tools</li>
<li>Automation via convention</li>
</ul>
</div>
</div>
<p><strong>PHP / Front-End Developers &#8211; CodeIgniter</strong></p>
<p><a href="http://codeigniter.com/"><img class="alignright" title="Code Igniter" src="http://codeigniter.com/user_guide/images/ci_logo_flame.jpg" alt="" width="150" height="164" /></a>I find that the more technical designers or coders will use an open ended framework like CodeIgniter.  It&#8217;s a decent MVC framework with a few extra libraries to make your common tasks easier.  CodeIgniter is based in PHP 4, which is a turn off to some.  CodeIgniter does not try to do everything for you, instead it does give you a loose structure to work with and build upon.</p>
<p>If you like to do things yourself, but want an MVC stack and some basic libraries to work with, then CodeIgniter is great.  There are also some spin-offs of CI that are worth checking out (notably Kohana, which is PHP 5).</p>
<div class="proscons">
<div class="cons">
<p><strong>Cons:</strong></p>
<ul>
<li>PHP 4</li>
<li>Libraries not flexible</li>
</ul>
</div>
<div class="pros">
<p><strong>Pros:</strong></p>
<ul>
<li>Great documentation</li>
<li>Large community backing</li>
<li>Fast &amp; simple</li>
<li>Open ended architecture</li>
<li>Decent libraries included</li>
</ul>
</div>
</div>
<p><strong>Backend Developers &#8211; Zend Framework</strong></p>
<p><a href="http://framework.zend.com/"><img class="alignright size-full wp-image-84" title="Zend Framework" src="/wp-content/uploads/2010/02/zend-framework.png" alt="" width="128" height="129" /></a>Zend Framework is a monster.  It is very daunting to beginners, and unfortunately because it has changed so much in the past 2 years, most of the blogs for it are inaccurate.  Zend Framework is the most complicated of the set, and it takes quite a large effort to get comfortable with it.  However, it offers such an enormous amount of flexibility that it has become my #1 choice for some time now.  You will need to be very hands on.</p>
<p>The best thing about Zend is how the code works.  You can more or less pick different components that you want and use them in other applications.  There may be a few dependencies, but compared to other frameworks it is miles ahead.  You can also easily drop in other libraries to work with your ZF application.</p>
<p>Zend is for creating serious web applications which may need a lot of external libraries or access points.  It is overkill for most websites; it&#8217;s meant for enterprise level websites or applications.  Zend&#8217;s documentation is also a little difficult to understand at first, as it&#8217;s more from an API perspective.  However, it has gotten better in the past few months to show big picture examples.  </p>
<div class="proscons">
<div class="cons">
<p><strong>Cons:</strong></p>
<ul>
<li>Steep learning curve</li>
<li>Slower codebase</li>
<li>Smaller community</li>
</ul>
</div>
<div class="pros">
<p><strong>Pros:</strong></p>
<ul>
<li>High quality code</li>
<li>Very flexible</li>
<li>Highly modular code</li>
</ul>
</div>
</div>
<p><strong>Summary</strong></p>
<p>There will never be a single framework that will fit everybody&#8217;s needs.  It&#8217;s best to analyze your goals, and then go from there.  Jumping to the biggest framework is never a good idea; neither is being stuck with a codebase that isn&#8217;t flexible enough and requires you to re-code everything.   Experiment with a few and see which one fits your needs the most.  Take into account things like community support, documentation, style, code quality, and efficiency.  Without communities working together to improve these tools, they become useless and outdated.</p>
]]></content:encoded>
			<wfw:commentRss>http://adrianschneider.ca/2010/02/picking-a-framework/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Installing Magento without Mcrypt</title>
		<link>http://adrianschneider.ca/2010/02/installing-magento-without-mcrypt/</link>
		<comments>http://adrianschneider.ca/2010/02/installing-magento-without-mcrypt/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 08:24:41 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[mcrypt]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zf]]></category>

		<guid isPermaLink="false">http://www.siradrian.com/blog/?p=21</guid>
		<description><![CDATA[Disclaimer: in a production environment, spend the extra time and resources to meet Magento&#8217;s requirements.  This post is about setting up a development environment.
I have had one hell of a time trying to get Magento up and running on my development server.  I have probably spent about 5 hours fighting with mcrypt and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/category/web-applications/magento-web-applications/"><img src="/wp-content/uploads/2010/02/magento-logo.png" alt="" title="Magento" width="128" height="128" class="alignright size-full wp-image-32" /></a>Disclaimer: in a production environment, spend the extra time and resources to meet Magento&#8217;s requirements.  This post is about setting up a development environment.</p>
<p>I have had one hell of a time trying to get Magento up and running on my development server.  I have probably spent about 5 hours fighting with mcrypt and for some reason, it is just not playing nicely with my setup (PHP 5.3, with everything compiled manually).  I brought in a server guru as well, and he had the same problem.  I think we both tore out some hair.   </p>
<p>I&#8217;ve hacked together some steps to get it up and running for developers who want to get their hands dirty quickly.<span id="more-21"></span></p>
<p><strong>Making Magento PHP 5.3 Compatible</strong></p>
<p>If you are running PHP 5.3, it takes a few tweaks to get Magento up and running.  </p>
<p>First one: edit /lib/Varien/Object.php, and find
<pre><code>    public function __toString(array $arrAttributes = array(), $valueSeparator=',')</code></pre>
<p> with replace it with
<pre><code>    public function __invoke(array $arrAttributes = array(), $valueSeparator=',')</code></pre>
<p>Step Two: Edit /index.php and change
<pre><code>error_reporting(E_ALL | E_STRICT);</code></pre>
<p> to
<pre><code>error_reporting(E_ALL ^ E_DEPRECATED);</code></pre>
<p>This may not be ideal, but it worked for me on my local machine.  Before I did this, I went in and tried to spot-treat several errors as they came up.  I was hoping it was just one, but after a few I caved and lowered the error reporting.</p>
<p><strong>Installing Magento without Mcrypt</strong></p>
<p>This extension was a major pain in the ass to (not) install.  I want my day back.  Anyway, I managed to isolate the sections to modify to avoid requiring this extension.  </p>
<p>Step One: edit /app/code/core/Mage/Install/Installer/Env.php, and find
<pre><code>                Mage::getSingleton('install/session')-&gt;addError(
                    Mage::helper('install')-&gt;__('PHP Extension "%s" must be loaded', $extension)
                );</code></pre>
<p> just above it, add
<pre><code>                if ($extension == 'mcrypt') {
                    return true;
                }</code></pre>
<p>Step Two: create /lib/Varien/Crypt/Base64.php and throw this into it
<pre><code>&lt;?php

class Varien_Crypt_Base64 extends Varien_Crypt_Abstract {
    public function __construct(array $data=array()) {
        parent::__construct($data);
    }

    public function init($key) {
         return $this;
    }

    public function encrypt($data) {
        if (!strlen($data)) {
            return $data;
        }

        return base64_encode($data);
    }

    public function decrypt($data) {
        if (!strlen($data)) {
            return $data;
        } 

        return  base64_decode($data);
    }
}</code></pre>
<p>Last Step: edit /lib/Varien/Crypt.php and change
<pre><code>    static public function factory($method='mcrypt')</code></pre>
<p> with
<pre><code>    static public function factory($method='base64')</code></pre>
<p>I&#8217;m not too sure why it&#8217;s not a configuration option, but oh well.</p>
<p>And yeah, this is by no means secure.  Far from it.  It works well enough to use locally and that&#8217;s all I really care about.  Hopefully this helps at least one other developer who is fighting with dependency hell.  If I missed out any steps I apologize.  I&#8217;ve been at this way too long.</p>
]]></content:encoded>
			<wfw:commentRss>http://adrianschneider.ca/2010/02/installing-magento-without-mcrypt/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Thoughts on vBulletin 4</title>
		<link>http://adrianschneider.ca/2010/02/thoughts-on-vbulletin-4/</link>
		<comments>http://adrianschneider.ca/2010/02/thoughts-on-vbulletin-4/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 07:42:21 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[vBulletin]]></category>
		<category><![CDATA[forums]]></category>

		<guid isPermaLink="false">http://www.siradrian.com/blog/?p=10</guid>
		<description><![CDATA[Clients have been asking me since its early beta stages what my thoughts are about vBulletin 4.  Usually I joke and spew out the usual garbage about how horrible it is.  I&#8217;m not saying it isn&#8217;t, but I think it&#8217;s time I give it a fair review.
Background
Before I go into much detail, let [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/uploads/2010/02/vbulletin.png" alt="" title="vBulletin" width="128" height="128" class="alignright size-full wp-image-11" />Clients have been asking me since its early beta stages what my thoughts are about vBulletin 4.  Usually I joke and spew out the usual garbage about how horrible it is.  I&#8217;m not saying it isn&#8217;t, but I think it&#8217;s time I give it a fair review.</p>
<p><strong>Background</strong></p>
<p>Before I go into much detail, let me begin by explaining my experience and background with vBulletin.  My first use with vBulletin was back in 2004 on a gaming site.  Since 2005, I have been developing on it as an application platform, and for a while, was doing it full time (2 years or so).  I am confident that I am one of the most experience vBulletin modders around.  I love vBulletin, though over the years I became annoyed with working with it due to the outdated codebase.   In the past two years or so, I have shifted most of my custom develoment to Zend Framework, which is of course at a much higher standard.</p>
<p>With the illusion of vBulletin 4 in my mind, I was very excited to begin looking at it. <span id="more-10"></span></p>
<p><strong>Internet Brands Acquisition</strong></p>
<p>During the very early stages of vBulletin 4, vBulletin and its company, Jelsoft, were aquired by their biggest customer: Internet Brands.  There are two very opposed reactions about this.  The good: since their business relies on vBulletin, they will take good care of it.  However, there is also the other way of looking at it: because their biggest competitors are also their customers, they have power to kill their competition and steer the product to their advantage.</p>
<p>Shortly after this took place, there were a lot of skeptics out there, but I didn&#8217;t think too much of it.  I&#8217;m an optimist, and thought it was about time vBulletin was picked up by a bigger company.  They needed the extra funding and development power.</p>
<p>After some time had passed, several of the core staff members began dropping like flies.  More rumors started pouring out about the takeover.  One of the reasons for this was IB is a US based company, and Jelsoft was a UK based company.  It makes sense, but it wasn&#8217;t the reason many of the developers left.  They were not happy with how the product was being managed.  Their core values were changing.</p>
<p><strong>Back to the Future &#8211; First Impressions</strong></p>
<p>When vBulletin 4 first hit vBulletin.com, it looked pretty bad.  However, I had some of that golden optimism reserved, because I know that it&#8217;s CSS based, and will take some time to get it right.  I don&#8217;t care too much how the stock software looks, because I (like many others) will be customizing it to death.  It took a lot of nagging, but we got some of the key things cleaned up.  There&#8217;s still a lot of work to be done, but I don&#8217;t see it changing much more at this point.</p>
<p><strong>Product Management</strong></p>
<p>This may not be an entirely relevant point, but it needs to be said.  Management has seriously dropped the ball &#8211; no, they kicked it over the fence.  They are so focused on making release deadlines set by upper management (surely to impress investors) that the product quality has gone to shit.  There are serious bugs in the &#8220;gold&#8221; (4.0) release that should have been fixed in a beta.  It&#8217;s ridiculous.  The whole 4.x release is a joke, because it&#8217;s not even a proper release.  It&#8217;s a (poor) transition of the 3.5-3.8 line.  It should have been called 3.9.  </p>
<p>In the forum itself, the only big thing worth mentioning is the new CSS layout.  The addition of the CMS is nice too, even though it&#8217;s a paid product.  However, it is nowhere near production ready.  I strongly recommend not to use it or vBuletin 4.x until things drastically change.  If I have an ounce of hope left for vBulletin Solutions / IB, then it will be held within 5.0. </p>
<p>Anyway, let&#8217;s get into some specifics.</p>
<p><strong>New Template System</strong></p>
<p>The new style management system is horrible to use.  I admit, it&#8217;s a step in the right direction, and I applaud forward movement.  However, it was done very poorly.  I&#8217;m glad there is a new template engine in place (though I prefer raw PHP), and I&#8217;m VERY glad that there is support for loops.  It will take some time, but I hope by 5.0 they will have everything converted to use loops in templates instead of hundreds of bit templates.  That&#8217;s what makes skinning so hard.</p>
<p>Skinning on 4.0 is more or less as painful as it was on 3.5-3.8.  </p>
<p><strong>New Default Design</strong></p>
<p>I am liking the new design more and more, but I still don&#8217;t think it&#8217;s up to the latest standards of what is out there right now.  I&#8217;m not talking about web standards, but just quality standards.  It looks good, but it&#8217;s not great.   With the addition of more UI people / designers, I expected a lot more.  </p>
<p><strong>New Codebase</strong></p>
<p>The new code is pretty good.  I think it&#8217;s a bit unnecessarily over-complicated though.  There are ways to create a very brilliant application design without making it seem complicated.  Simple code is readable code and it takes a lot more planning.  I&#8217;m not going to complain though, because it&#8217;s about what I expected.  They did good.</p>
<p>However (and this is a big one), the new codebase is barely used.  It&#8217;s only used by the CMS, because vBulletin itself is still in transition.  Really then, you are not getting much of anything new in 4.0 unless you get the suite.</p>
<p>I haven&#8217;t seen a single developer utilize the new codebase yet.  Every single person I&#8217;ve talked to has only converted the templates to the new syntax.  They really should have used something more simple for the template variable assignments.   Like I said: simple code is well planned code.  This does not appear to be well planned.</p>
<p><strong>Another Look</strong></p>
<p>You&#8217;ll notice a lot of the complaints I have are because vBulletin is in a transition stage.  If they were to push this honestly as a transition release, and perhaps called it 3.9 and didn&#8217;t push so hard for pre sales, then this wouldn&#8217;t be all that bad.  It&#8217;s a step in the right direction.  It&#8217;s a shame that management had to butcher their great reputation and basically lie to all the customers.</p>
<p><strong>Bottom Line</strong></p>
<p>Alright, so in all fairness, it&#8217;s not a horrible release.  However, there isn&#8217;t much new to justify upgrading in my opinion.  It&#8217;s also not nearly as stable and deserving of a gold title as the previous branch.  My advice?  <strong>don&#8217;t waste your money on it</strong>.  Wait for 5.x.  Hopefully they can salvage what little reputation they have left before IPB steals any more customers.</p>
]]></content:encoded>
			<wfw:commentRss>http://adrianschneider.ca/2010/02/thoughts-on-vbulletin-4/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
