Thursday, March 31, 2011

Ideas of March, or Thank you, Mr. Shiflett.

We do need more blogging.  Tweets are fine for their intended purpose, but there is only so much idea one can squeeze into so little space.

I like blogs because of what I learn from them; they encourage me to stay current, they expose me to new thoughts and they help me stay connected with the community.

I like blogs precisely because they aren't real-time. They are the result of observation and reflection.  I get to read someone's more fully-developed thoughts, communicated in full sentences, with examples, and even paragraphs!  Blogging forces one to crystallize one's thoughts, and teaches us how to communicate more effectively.  True written communication is not dead.  Blogs make me think; I not only like that, I need it.

I like being able to go back to a blog post I've bookmarked as a reference, finding again something I needed once, and need again from time to time. In addition, I get to see how the concept develops over time, as commentors contribute their thoughts and opinions on the subject.

Blogs also inspire me to contribute some of what I may have learned along the way.  This is where I've fallen down, terribly, often believing that I really didn't have much to say that would be of use to others.

I see otherwise now.  I've been teaching novice programmers PHP and Zend Framework with Zend Technologies since autumn 2008.  I get asked a lot of questions about programming, code design, object-oriented development, and testing.  Most of my colleagues are advanced developers, and they often blog about advanced techniques, and although those techniques help make a developer's life easier, some of the people I encounter daily aren't quite ready to take advantage of particularly advanced development practices.

I pledge to blog more often, and help flatten out the learning curve for the newbies.  We were all newbies, once, and if we're committed to lifelong learning, and to keeping our skills current, we remain newbies, in at least one area, all the time.

See you briefly on Twitter with a #ideasofmarch tweet.

Zend Framework Autoloading - Finding Your Library Classes

Attention Zend Framework beginners.  Since today is the final day for me to get around to contributing - in some small way - to The Ideas of March, which encourages people to blog more often, I offer up the following.

If you find yourself using require_once statements in your Zend Framework applications in order for ZF to find your library classes, in spite of using Zend_Application - which you know establishes autoloading by default - then there is one simple thing you need to add to your application's config file, typically configs/application.ini, to fix the problem.  End your frustration, and read on.

Assuming a directory structure something like this (my "vendor prefix" of EAI stands for Everetts Associates, Inc.):
application/
data/
docs/
library/
        EAI/
            Mail.php
public/
scripts/
temp/
tests/

and a class named EAI_Mail in the Mail.php file, and assuming your library is on your include_path, all that is needed is a line like this in application.ini:

autoloaderNamespaces[] = "EAI_"

Zend Framework's autoloader is already configured to match class prefixes Zend_ and ZendX_.  What you're doing by adding the above line to the application's config file is register your library prefix/namespace with the autoloader.  The include_path was not your problem, the problem was that ZF wasn't acknowledging your class prefix.

Now you can strip out those require_once statements for a bit of a performance boost.

Happy coding.