handling checkboxes in symfony forms 1.2

Checkboxes aren’t really covered in the tutorial for forms in 1.2.  However, it’s covered pretty well on the blog over here:

http://www.symfony-project.org/blog/2008/10/14/new-in-symfony-1-2-make-your-choice

One thing to note:  if you need a multiple checkboxes for one value (in php it’s handled like so: varname[]), you would use the sfWidgetFormChoice with the multiple=>true and expanded=>true.

Also, if it’s an array of values, use sfValidatorChoiceMany instead of sfValidatorChoice.

-d

escaping output in symfony – wtf is going on????

Ok, I was a little confused as to what the hell was happening when I escaped my output in symfony.  It looks like the 1.2 framework takes all your values and objectifies them, putting them into classes.  For your arrays, they go into sfOutputEscaperArrayDecorator.

What this means is that now when you are trying to use the array in a view, you need to call the getRaw function that sfOutputEscaperArrayDecorator has.  SO:

in your action:

$my_array = array(1,2,3,4);

in your view print_r($my_array) will throw in error.  what you need to do instead is:

print_r($my_array->getRawValue());

I haven’t tested the rest of the objects out, but im assuming you can get the actual object by calling getRaw() on the variable name.

-d

You is the closer!

So I worked on a quick one pager site (http://www.isthecloser.com) with a co-worker (Jason) from Tribal that merged two wav files to create a funny short wav clip.  Check it out.

To build the site, I used two technologies:

1) Flite – an open source text-to-speech system developed by CMU.  It was a low quality wav, but did the job well.  I also used Espeak, but the code looked like it required the server to a sound card installed, which mine does not.  So I switched over to flite instead.

2)  SOX – an open source sound exchange application.  I originally used the default one that came with CentOS 5, but it lacked the feature of sequencing the sounds together instead of merging them on top of each other.  So I uninstalled the default rpm and downloaded the code base and recompiled the latest version.

The code wasn’t too complicated, it was just figuring out how to get all the stuff to work together.  First get flite to spit out a wav:

/usr/local/bin/flite -t “‘ . $name . ‘” -o /tmp/closertemp/’ . $rand . ‘.wav’

the -t option is to use the text that’s passed in instead of a file

then I push it to sox:

/usr/local/bin/sox –combine concatenate /tmp/closertemp/’ . $rand . ‘.wav /tmp/TheCloser_1.wav /tmp/’ . $rand . ‘.wav’

the rand # is to make sure i always produce a unique file name for every request.

wrap-up of mysql meetup featuring cto of huffington post

So I went to the NY MySQL meetup.  It was pretty interesting to hear first-hand the thoughts of someone using MySQL in a heavy trafficked environment.  They’re essentially running huffpo on a heavily customized movabletype system (php) on 14 front end web servers, 4 memcached servers and 7 mysql servers.  They couldn’t move to MySQL on ec2 because the max memory limit for their big servers were too small (they must have some heavy hardware going).

OK, so onto the interesting stuff:

They have a dual master setup, while running 5 slaves using MySQL 5.0.x and apparently almost all tables are on InnoDB.  The second master was primarily for a hot backup of the site.  They’ve setup memcache to take load off the mysql servers, and interestingly enough, they’ve moved session storage actually into memcache instead of mysql.  Their reads come from the slaves, but HuffPO CTO said specifically that it’s only for stuff that can be a few seconds behind the prod server.  Any sort of statistical stuff comes off the slaves as well.  One interesting thing they noted was that at times of extreme load, they have the ability to turn on and turn off features.  Also, they’ve mentioned that they add another level of cache upfront using Akamai to deliver dynamic pages.

They’re currently shifting to using ssd’s for their table storage and a new san for their log storage on a new hardware.  They’ve also setup a load balanced vip for clustered access to the slaves.    Overall I thought it was interesting to hear how they’ve setup their enviornment.

One thing they did note was that they had tried to use memcached on each of their 14 web servers but that they had synchronization issues across the servers, each cache would lose itself then force a rehash across all the servers.  Instead of keeping it on 14 servers, they consolidated to run it on 4 servers, which upped the cache hit rate from the 25% that they were getting.

An interesting thing he did mention was that they give a potential hire a link to an ec2 image that need to use for a test.  If they can’t pass that test then they’re most likely not technical enough to go on.  Pretty great idea.

symfony forms 1.2: adding multiple postvalidators

Here’s a tip for the symfony folks:

adding multiple postvalidators:

$this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare(‘password’, sfValidatorSchemaCompare::EQUAL, ‘password_again’, array(), array(‘invalid’=> ‘Password and Password Again do not match.’)));
$this->mergePostValidator(new sfValidatorSchemaCompare(‘email’, sfValidatorSchemaCompare::EQUAL, ‘email_again’, array(), array(‘invalid’=> ‘Email and Email Again do not match.’)));

If you use sfValidatorAnd in your forms, the individual error messages no longer matter.  The error message of the sfValidatorAnd is used instead.

‘email’             => new sfValidatorAnd(array(
new sfValidatorString(array(‘max_length’ => 60)),
new sfValidatorEmail()), array(), array(‘required’=>’Email is required.’, ‘invalid’=>’Email is invalid.’)),

Finally, to get to all the errors in the form:

$form->getErrorSchema()->getErrors()

to get to all the global errors in the form:

$form->getGlobalErrors()