jQuery event handling best practice

Anonymous functions are usually used extensively in jQuery events handling, however, anonymous functions are difficult to debug, maintain, test, or reuse.

A better way is to use object literals as in this example:

 

//BAD
$(document).ready(function() {  
  $('.status .delete').click(function(e) { //Do something });  
  $('.status').dblclick(function(e) { //Do the same thing });
});

//GOOD
var bindingObject = { 
onReady : function() { 
  $('.status .delete').click(bindingObject.deleteTweet);    
  $('.status').dblclick(bindingObject.deleteTweet);  
},  
deleteTweet : function(e) { //Do something }
};

$(document).ready(bindingObject.onReady);

 

10 Symfony 1.4 best practices

Here is a list of 10 Symfony 1.4 best practices:

  1. Manage the view withing the view, try to avoid the use of view.yml, this will simplify future interventions by designers who are not necessary familiar with YML.
  2. Always call a redirect after posting data, this will inhence security and avoid content duplication in the database.
  3. The template must contain PHP alternative templating syntax.
  4. Only deploy production front controllers in production.
  5. Change the session_name param under the storage section in factories.yml
  6. Make sure a csrf_secret is defined in the settings.yml file.
  7. always apply Symfony coding standards http://trac.symfony-project.org/wiki/HowToContributeToSymfony
  8. Always create custom 404 and 500 error pages.
  9. Use sfLogger for debugging instead of echoing variables
  10. Use Symfony tasks system for CLI batch sripts.

Symfony 1.4 Cheat Sheets

39457302-SymfonyViews

Can’t remember all of Symfony 1.4 commands, syntax, architecture, …? there is an amazing collection of cheat Sheets availeble from http://www.symfony-project.org/more-with-symfony/1_4/en/03-Enhance-your-Productivity under the “Cheat Sheets” section, here is some of the most interesting ones.