Generating ORM classes (doctrine, propel, zend db table) with MySQL workbench and schema exporter

Just a short post to let you know that I just found this awesome github project that I need to checkout some day, to generate model files automatically.

  • In doctrine/propel you generate ORM classes based on annotations, yaml or xml.
  • In MySQL workbench, you can completely design a schema file and “migrate” the schema file against a database. The changes will be detected and will be written in an update script.

With these two tools, developing with database entities should be a breeze.

WordPress gravatar / avatar bug: comment email instead of admin email

The following can happen:

  1. You make a site for a customer
  2. You insert some comments that your customer provides.
  3. Gravatar uses the admin email instead of the comment author email.

How do you get a gravatar image for the comment email instead of the author email?

You need to write a filter function. the get_avatar filter passes the img code as first param, and the id of the author(you) or an emailaddress as the second.

Continue reading “WordPress gravatar / avatar bug: comment email instead of admin email” »

ModRewrite Shenanigans

So I am trying to figure out how to set up a router that can set up site hyperlinks that work with a mod_rewrite situation. I really like PATH_INFO for this as I can use this for apps in subdirs (testing environment for example). This way, you can use and still have the fallback url working:

If you place the following code in your htaccess, you can enjoy this technique.

#Force Path info in PHP, gets overridden in RewriteRule.
SetEnvIf Request_URI "^/?" PATH_INFO=/
# Mod Rewrite is off by default.

<IfModule mod_rewrite.c>

    # Update environment variable with some info. 
    SetEnv MOD_REWRITE 1
    RewriteEngine On

    # Webroot directory relative to index.php
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/?(robots\.txt|favicon\.ico|index.php)$
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]

How does it work?

This way, you can use the following logic in your code to generate a correct url.

  1. Construct a variable to prepend:
    1. Take the directory name of the SCRIPT_NAME environment variable if the MOD_REWRITE environment variable is 1…
    2. … Or take just the SCRIPT_NAME environment variable.
  2. Add a trailing slash if missing.
  3. Add the url to a page you want or use the PATH_INFO environment variable for the current page (canonical links).