youlove.us

Monday, 27 October 2008

youlove.us

Fantastically designed site from a new web development firm.


Espresso

Monday, 27 October 2008

Espresso

A new web development application from the makers of CSSEdit. Interesting, but from the screenshots alone it’s hard to see what all the fuss is about. Looks like a more loosely integrated Coda alternative.


A Smarter MAMP

Friday, 24 October 2008

A Smarter MAMP

Great article about setting up the built-in-but-inactive DNS Server on Mac OS X to enable almost automatic creation of new local development virtual hosts. A must read for anyone who knows the annoyance of having to edit the hosts file and an apache config file (among other things) whenever you want to add a new local development site.


Database Migrations in Doctrine and Propel

Friday, 24 October 2008

I just read Jonathan Wage’s post on Doctrine’s new migration features. Specifically, he goes into the new Diff Tool (which can automatically generate migrations when you change your schema) and Down Automation which replaces the classic up() and down() methods with a singular migrate($direction) method. It looks promising, but I have yet to actually build something with Doctrine. This looks to be really elegant though and may push me over the edge to jump in to Doctrine on a new project. The sooner the better I suppose since Doctrine will be bundled with Symfony 1.2.

Also, for Propel users, Kris Wallsmith is working on adding migrations to Propel via the Symfony sfPropelPlugin to replace the older and much more manual sfPropelMigrationsLightPlugin. It looks promising but I haven’t read anything recently about progress.


CSS Browser Selector

Friday, 24 October 2008

CSS Browser Selector

An interesting and elegant solution for those looking for a way to target specific browsers and/or operating systems with differing CSS. It’s a (less than) 1kb JavaScript file that will add a class name to your document’s html tag with the browser and OS of the client machine so you can write CSS that targets certain browser and operating system configurations in a standardized way.

This is similar to a method I use for adding Symfony module and action selectors to the body tag.


Using the Zend Framework with Symfony 1.1

Tuesday, 21 October 2008

I’ve written about using the Zend Framework within Symfony before but things have changed a bit in Symfony 1.1 so I wanted to post an update with a new Symfony 1.1 compatible approach to loading and using the library from within Symfony. The biggest change that has happened since my previous article is that the sfZendFrameworkBridge has been removed from Symfony. This is actually a Good Thing since, as you’ll see in a moment, there is now a more elegant approach to loading external libraries.

Most of the steps are the same as those outlined in the afore-linked article so you may want to read it before going further. The main difference will be how we get the Zend Framework files to autoload.

Getting the Library

This article assumes that you’ve placed the Zend Framework files in <sf_project_root>/lib/vendor/Zend just as we did the last time around. Note though, that the Zend Framework subversion repository went through a bit of a restructure, so if you’re linking to lib/vender/Zend via svn:externals you’ll want to use this updated format on lib/vendor:

Zend http://framework.zend.com/svn/framework/standard/tags/release-1.6.1/library/Zend

Linking the Library to Symfony

Now, to link the Zend Framework and allow auto-loading of class files, all you need to do is add a few lines to your application’s configuration class file. If your app is named frontend then the file you’ll need to edit is located at apps/frontend/config/frontendConfiguration.class.php.

Modify your initialize() method to include the following:

public function initialize() 
{ 
  parent::initialize();
  
  $sf_zend_lib_dir = sfConfig::get('sf_lib_dir').DIRECTORY_SEPARATOR.'vendor';
  
  set_include_path($sf_zend_lib_dir.PATH_SEPARATOR.get_include_path());
  require_once($sf_zend_lib_dir.DIRECTORY_SEPARATOR.'Zend'.DIRECTORY_SEPARATOR.'Loader.php');
  spl_autoload_register(array('Zend_Loader', 'loadClass'));
} 

… and that’s it. Clear your cache (./symfony cc from your project root) and you should be good to go. Creating an instance of a Zend Framework class is as easy as something like this:

$pdf = new Zend_Pdf();

Zend_Pdf will be auto-loaded for you.

The information in this article was gleaned from a post by Dustin Whittle and also one from Kris Wallsmith.


Symfony 1.1's New Architecture

Monday, 06 October 2008

I came across this post from a few months ago on the Symfony site:

http://www.symfony-project.org/blog/2008/06/23/the-symfony-1-1-architecture

It’s a really interesting overview of the new decoupling of core classes that Symfony 1.1 provides. This is particularly useful information if you’re designing something that needs to be fast and trim and you don’t want to load the entire Symfony framework on every request. Essentially you can create a custom sub-framework out of Symfony components for just the pieces you need. This saves a lot of the overhead of having to load extra components that you won’t use.

Worth a read.


Wildcard Subdomains in Plesk

Thursday, 28 August 2008

In a recent project, I had to enable wildcard subdomains in Plesk so that I could use dynamic subdomains with symfony. The answer was to manually add an Apache directive to the domain’s configuration and was found in a Knowledge Base article from Parallels: http://kb.parallels.com/en/955

I wanted to post this just in case someone else runs into the same issue trying to use the dynamic subdomains front controller with a domain set up through Plesk. This was Plesk 8.4.0 running on a Media Temple Dedicated Virtual(dv) hosting plan, but should work with older versions of Plesk as well. If you’re not sure what a vhost.conf file is, there are several tutorials online or you can check out the official Plesk documentation (here’s the PDF you’d probably want to take a look at).


A Quick Look at OmniFocus Versus Things

Tuesday, 26 August 2008

Via The Apple Blog:

There are dozens of productivity applications for your Mac, and a few for your iPhone. But there’s one application that’s available on both your Mac and your iPhone… OmniFocus.

Well, it’s definitely one application that’s available for both iPhone and Mac OS X, but it’s not the only one. As my voyage with Things continues, I figure I’d do a quick comparison of the OmniFocus features The Apple Blog listed with those from Things (which is still in beta). This is in no way a conclusive list, but I figure it’s a good comparison of the features most people care about.

Desktop Versions

  Inbox Quick Entry Shortcut Email Entries Backups
OmniFocus Yes Yes Yes Yes
Things Yes Yes No* Yes

* Does anyone really use this? Especially when there’s an iPhone pocket version?

Overall I’d say this is a pretty close match-up. The ability to email entries was a nice plus when all I had was the desktop version of OmniFocus. I could basically email myself a task that would later be automatically added to OmniFocus on my laptop. Unfortunately I never really used this since I pretty much always forgot the syntax. So, I’d end up emailing myself a note to manually add some task to OmniFocus. Something like “Don’t forget to write an article comparing OmniFocus to Things!” etc.

iPhone Versions

  Adding New Tasks Location Aware Syncing (with the desktop version)
OmniFocus Yes Yes Yes
Things Yes No Yes

The location aware functionality that OmniFocus for iPhone has sounds really interesting, but I’m curious as to whether or not it’s useful in practice. This is the one reason I’m really considering buying OmniFocus for iPhone, but I have a hard time believing I’d really use it. I’ve purchased OmniFocus, and Things for iPhone (the desktop version of Things isn’t on sale yet) but haven’t really had a compelling reason to try out the iPhone version of OmniFocus. Wouldn’t it be faster to just click the “grocery store” context rather than having to wait for Core Location to locate you and then tell you, “Hey! You’re at a grocery store! You could buy some eggs and milk!” This might be more useful if applications were allowed to run in the background. Then you could be notified, if say, you were driving by a grocery store and there was something on your list, but the fact that you have to have the app running makes me believe that it would be more of a novelty than anything.


Using Symfony Partials In DHTML and Ajax

Thursday, 21 August 2008

Often times when building dynamic applications with Ajax or DHTML you’ll come across the need to use a snippet of html code over and over. On the server side, this is typically accomplished with the use of reusable pieces of code that get stitched together to form a single web page. Wouldn’t it be nice to be able to use the same code fragments that are used to render the page on the server side, on client side?

Symfony, for example, allows for several different types of these code fragment components, the most basic being the “partial”. Partials are particularly useful when you need to add or update content to a page via Ajax.

For example, here’s a simple set of select boxes:

select lists

You can dynamically add a new select box by clicking the “Add another country” link or remove one using the “Remove” link. Pretty standard stuff. To generate one of these rows, we could include a partial from within our main template. Something like this:

<div id="country_lists">
    <?php include_partial('preferences/countrySelect', array('countries' => $countries, 'first' => true)); ?>
</div>

And here’s the partial’s contents:

<div class="country_list">
    <?php echo select_tag('countries[]', options_for_select($countries, null, array('include_custom' => '-- Select Country --')))?> &nbsp; 
    <?php echo link_to('Add another country', '#', 'class=add') ?>
    <?php if (!isset($first)): ?>&nbsp; | &nbsp; <?php echo link_to('Remove', '#', 'class=remove') ?><?php endif ?>
</div>

… as you can see, I’m doing a check to see if the partial we’re rendering is the first in the list and if it is, the link to remove the row is not included. Also, I’ve named the select_tag countries[] so that PHP automatically collects all of the results for these tags into one array on submission, regardless of how many the user added.

So far this is all really standard stuff. The interesting part comes when you need to dynamically add another row through javascript. For the javascript interactions I’ll be using jQuery and some simple event delegation. Here’s an example of how it might work:

<script type="text/javascript" charset="utf-8">
    // event delegation
    $('body').click(function(event) {
      var element = $(event.target);

      // "add" link clicked
      if (element.is('a.add')) {
        element.parent('div.country_list').after("<?php echo escape_javascript(get_partial('preferences/countrySelect', array('countries' => $countries))) ?>");
      }
      // "remove" link clicked
      else if (element.is('a.remove')) {
        element.parent('div.country_list').remove();
      }
    });
  });
</script>

Note that since we’re writing this jQuery code from within a symfony template, we have access to all of the Symfony goodness. For example, I’m echoing a partial from right within the jQuery after() call. Using simply include_partial directly would most likely result in a javascript parser error as the countrySelect partial contains line-breaks and both single and double quotes, so we’re using get_partial instead. The call to get_partial returns the partial as a string instead of echoing it directly. Then I’m wrapping it with a call to escape_javascript which is a standard symfony helper that will escape all of the potentially problematic characters so that the string can be used within a javascript call.

So now, after the page has been rendered, the partial’s code is injected right into the jQuery call. This is basic DHTML, but could be further extended with Ajax if we needed to insert a partial with dynamic content. New in Symfony 1.1 is the ability to render a partial directly from within an action so you don’t have to create a template that would just hold an include_partial call. This is perfect for Ajax. See the API docs for more information on renderPartial().