Code

A land full of candy for Geeks!

PHP custom debugging functions

Here is another debugging helper for Symfony, CodeIgniter, Kohana and Zend frameworks or your applications. Normally you would use var_dump() or print _r() for debugging but dumping the data without xdebug always a pain.

I use these custom functions depending on type of data whether an array or a class to debug my code which makes it more friendly and human-readable.



<?php

function my_print_r ($param$bool TRUE) {
    
preprint_r($param$bool), FALSE);
}

function 
my_var_dump ($param) {
    
pre(var_dump($param));
}

function 
my_debug ($param) {
    if (
is_object($param)) {
        
pre('Object: ['.get_class($param). '] => '
           
print_r(array_keys(get_object_vars($param)), TRUE), FALSE);
    }
}

function 
my_debug_in ($param) {
    if (
is_object($param)) {
        
pre('Object: [' .get_class($param).' ] => Array'FALSE);
        foreach (
get_object_vars($param) as $key) {
            
my_debug($key);
        }
    }
    if (
is_array($param)) {
        
my_print_r($param);
    }
}

function 
my_class($name NULL) {
    
$class = new ReflectionClass($name);
    
my_print_r(Reflection::export($class));
    
}

function 
pre($param$bool TRUE) {
    if (!
ini_get('xdebug.default_enable') || !$bool) {
        echo 
"<pre>".$param ."</pre>\n";
    }else {
        echo 
$param;
    }
}

?>

Symfony and sfDoctrineGuard missing installation point

If you are getting the 500 error (Call to undefined method myUser::isAnonymous.) after installing the sfGuardDoctrine plugin i.e

Call to undefined method myUser::isAnonymous.

Add these lines in your apps/app name/config/factories.yml to make to pluging to work.

all:
  user:
   class:  sfGuardSecurityUser

Using th native MySQL ENUM type in Symfony 1.4 and Doctrine

To use the native MySQL ENUM type in Symfony and Doctrine you will have to update your "project/config/databases.yml" and add the "use_native_enum" directive under "attributes" i.e:
      attributes:        
         use_native_enum: true
         use_dql_callbacks: true
         default_table_collate: utf8_general_ci
         default_table_charset: utf8

Full Version

40 Most Needed Drupal Modules

Here are my top 40 Drupal modules that seem to happen more often I am using them in my Drupal projects.

 1. addtoany
 2. blocks404
 3. boost
 4. cacherouter
 5. canonical_url
 6. captcha
 7. cck
 8. custom_breadcrumbs
 9. date
10. diggthis
11. filefield
12. gravatar
13. htmlpurifier
14. image_caption
15. image_fupload
16. imageapi
17. imagecache
18. imagecache_profiles
19. imagefield
20. imagefield_crop
21. imagefield_tokens
22. imce
23. imce_wysiwyg
24. menu_breadcrumb
25. montharchive
26. nodewords
27. page_title
28. pathauto
29. seo_checklist
30. tagadelic
31. taxonomy_breadcrumb
32. taxonomy_manager
33. taxonomy_menu
34. taxonomy_vtn
35. token
36. twitter
37. views
38. workflow
39. wysiwyg
40. xmlsitemap

URL rewriting and add www to .htaccess for hosting multiple domain or multi sites

Adding the www to URL in .htaccess for hosting multiple domain or multisites and handle www issue for canonical URLs.
    ##Adding the www
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
    RewriteRule ^(.*)$ "http://www.%1/$1" [L,R=301]

The other way around you can removing the www from URL.