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.

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()

symfony error: Duplicate table found: propel

Some problems occurred when executing the task:
build-propel.xml:479:1: Duplicate table found: propel.
build-propel.xml:465:121: Execution of the target buildfile failed. Aborting.
If the exception message is not clear enough, read the output of the task for more information

So when you’re reverse engineering a database schema, you’ll likely get this error if you have plugins installed and you try to do a propel:build-model. For instance, if you have a an existing database and you’re doing a ./symfony propel:build-schema, it will go in and create a new schema.yml for you.  But, you have tables in there that the plugins will take care of, so there will be a conflict.  To fix this, you should go into the generated schema.yml and clear out the additional tables.  Then run the build-model again.

Customized 404, 500 error pages in symfony

Ok, the documentation on the web is a little confusing. So let me try to clarify it:

404 pages can be customized and used in the action/template settings.
500 pages can not not customized to use an action/template setting.

404 pages can be linked to action/template settings in the settings.yml file of your application by adding:

.actions
error_404_module: module_name
error_404_action: action_name

500 pages need to be setup in your web/errors/ directory under the error500.php page. This page does not take a template and is its own page.

UPDATE: in symfony 1.2 it looks like the error pages are now in config/error/error.html.php  (annoying)

-d

why should I use a framework?

I’m a huge proponent of using frameworks when developing sites.  The biggest advantage of using a frameworks is that code is generally developed in an organized and structured way.  It makes bad developers conform to one uniform developing method instead of coming up with some crazy cockamamie structure (and let me tell you, i’ve seen some crazy ass stuff).  Of course you shouldn’t be hiring bad developers, but that’s another blog post in itself!

When picking a framework, I would recommend using a framework that is documented to death.  By picking up the framework documentation, another developer can figure out where the code is and instantly get started on working on the code because all the code is placed into specific agreed-upon areas.

In addition to good documentation, the framework should be highly object oriented.  While some of the .NET guys reading this think ‘wtf are you talking about… everything is OO’, not all PHP frameworks that i’ve seen are OO.  Object oriented frameworks are beautiful.  They allow multiple developers to work on the same object without stepping on each other’s feet (using svn, of course).  Without a nicely patterned OO framework, the code becomes an unmanageable spaghetti mess!

I would also urge you to use an open source framework.  In my experience, a popular open source framework has been poked at by thousands of developers and has stood the test of time.  While this may not be the case all the time, it generally is.  The benefit is having a support community that can help you answer questions on how to do things.  Also, there may be some community developed plugin that you can use instead of building something from scratch.

An argument that i’ve encountered in the past is ‘frameworks are slow’.  While they do add overhead, I find that time-to-market is much more important to a business than is scalability at day zero.  All frameworks can be tweaked for performance increases.  In the end, if on framework can serve 10 more pages than another, it doesn’t really matter that much.  Cloud computing is so easy to do nowadays, it’s trivial to launch another instance of your web server.

This isn’t to say your code shouldn’t be optimized.  You framework should be customizable enough to allow different database configurations (read/write or sharding) as well as customizable enough to output static html if need be for lighthttpd setups for front end servers.

Some PHP frameworks that i’ve used and that I’m a huge fan of are:  Symfony, CodeIgnitor, CakePHP (in this order).

Again, feel free if you want to argue/dispute this in the comments, or if you have some questions feel free to email me.