Here’s a useful .htaccess snippet if you need to exclude a folder from your .htaccess rewrite.


RewriteEngine On
RewriteCond %{REQUEST_URI} !^/exclude-folder/.*$
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1

For web development and writing mostly code in PHP / Symfony, I prefer PHP Storm.  I do also use the Eclipse IDE and have been happy with its latest version, Eclipse Luna, since it has a Symfony, Twig and YML modules which are full of code helpers and on-the-fly validation and overall it is very expandable.

One thing I do like is changing the themes of different code environments, it’s easier to get in the mode.  Also, I like black screens, after staring a the monitor all day, I think it’s much easier on the eyes than white backgrounds.  I might think about changing my WordPress admin theme, come to think of it!

Changing the theme in PHP Eclipse is fast and easy:

1.  Go to Help > Install New Software…

2.  In top field, paste “http://eclipse-color-theme.github.com/update”  and click the “Add” button

3.  Restart Eclipse then go to Window > Preferences > Appearance > Color Themes  and select your favorite theme.

Eclipse-change-theme-ide

I personally like “Retta” or “Vibrant Ink”, I like to use one theme for PHP projects and a different color theme for Java, it helps keep the mind in one zone or the other, but that’s just a personal preference.  Eclipse has come a long way and as a free IDE, it is amazing in its versatility.

A great product and community keeps it stable and always on the leading edge of innovation.  I am looking forward to playing with it when I am learning the “Play” Java framework, which is eerily similar to Symfony 2.5.  Makes you wonder if they’re not the same or who came along first…  Either way, I sure am grateful they’re out there!

Visit www.Eclipse.org to learn more.

 

– Aaron Belchamber
www.AaronBelchamber.com

 


Here is a great introduction and overview if you are just learning Java or Scala. The Play framework is very similar to Sensio Lab’s Symfony PHP framework. Learn one and you already know probably 70% of the other!

– Aaron Belchamber


Sometimes, you may find yourself needing to select a value or record from a database and hold that record so you can update it without any other process intervening. There are a lot of instances you may need to “lock” the record to a process to ensure no other process can “claim” it as well.

Perhaps your website has users who can “claim” a limited number of free giveaway items. Without “locking” the record, you can have duplicates “claiming” the giveaway and go over the number of free items you’re giving away. That’s just one practical example, so in MySQL you would use “SELECT FOR UPDATE” instead of just the “SELECT” statement.

If you are using Symfony and Doctrine, here’s the “SELECT FOR UPDATE” version for “DQL” (Doctrine Query Language). You set the “Lock Mode” to PESSIMISTIC_WRITE:


$query = $this->em->createQuery('SELECT …'); 
$query->setLockMode(LockMode::PESSIMISTIC_WRITE);
$em->find($class, $id, LockMode::PESSIMISTIC_WRITE);


Sometimes you may need to modify the standard form type by customizing some of the form fields, adding form fields, changing the list of form choices, omitting certain input, and making other changes. It’s easier to alter an existing form type than duplicating it just to make a few modifications, which helps follow the DRY principle (Don’t Repeat Yourself!)

Symfony encourages, and makes it easy to stay with OOP (Object Oriented Principles) by keeping to DRY, so you not only write less code, you will have less to maintain. Not to mention your code is more reliable, which is why it is recommended to reuse form types and modify them as needed in different situations, just like you would other objects in your system.

Here are some more helpful Symfony form tips and snippets.

Set the form action inside buildForm():


public function buildForm(FormBuilderInterface $builder, array $options)
{
   $builder->setAction($path);
}

Change the forms “action” url path in the createForm():

$form = $this->createForm(new WhateverFormType(), $object, array(
          'action' => $this->generateUrl('action_route'),
));

 

Customize form values and attributes in the createFormBuilder():

$form = $this->createFormBuilder($task)
  ->setAction($this->generateUrl('target_route'))
  ->setMethod('POST')
  ->add('task', 'text')
  ->add('dueDate', 'date)
  ->add('save', 'submit')
  ->getForm();