Vastermonster is Paul Thrasher's personal blog. This is my space to write and post whatever I'm into at the moment. I will mostly post about php code, design, strange videos, internet chaos, simplicity and cleverness -- fairly in-often.

Speed up your slow Firefox DNS lookups in Leopard OS X by turning off IPv6

Apple › System Preferences › Network › Advanced › TCP/IP tab › Configure IPv6 › Off

via

November 26th, 2008 / Tags: os x, firefox / Trackback

Find the Character Map in Leopard OS X

Apple › System Preferences › International › Input Menu
Check “Keyboard Viewer” and “Show input menu in menu bar”
Flag Menu › Show Keyboard Viewer

via

November 26th, 2008 / Tags: os x, design / Trackback


rm -rf ./*/.DS_Store
rm -rf ./*/.svn

Tip for removing the .DS_Store files and .svn folders recursively throughout a folder tree.

November 20th, 2008 / Tags: code, linux, command, tip / Trackback

Adding and/or injecting error messages into Symfony 1.1 Forms

Symfony 1.1 does a great job handling forms and form validation but say you have a few external forces checking the validity of the user submitted data, such as Paypal. Paypal would love to return it’s own error messages (thank you very much!) and tie it to a particular form field (say, the credit_card field).

Place this method into “symfony_project/lib/form/BaseFormPropel.class.php”:

<pre id="geshi_code">/**
   * Define error
   *
   * author Dmitry Nesteruk, Andrey Kotlyarov
   * param string $fieldName
   * param string $message
   * return void
   */
  public function defineError($fieldName, $message)
  {
    $checkName = 'check_define_'.md5($fieldName);
    $this-&gt;getErrorSchema()-&gt;getValidator()-&gt;addOption($checkName);
    $this-&gt;getErrorSchema()-&gt;getValidator()-&gt;addMessage($checkName, $message);
    $this-&gt;getErrorSchema()-&gt;addError(
	    new sfValidatorError(
		    $this-&gt;getErrorSchema()-&gt;getValidator(),
		    $checkName,
		    array(
		    	'value' =&gt; sfContext::getInstance()-&gt;getRequest()-&gt;getParameter($fieldName),
			    $checkName =&gt; $this-&gt;getErrorSchema()-&gt;getValidator($checkName)
			    )
	        )
	    );
  }

And use it like so:

<pre id="geshi_code">$this-&gt;form = new BillingForm();
$Paypal-&gt;sendPayment();
if(in_array($Paypal-&gt;error_codes,10527)){
	$this-&gt;form-&gt;defineError('credit_card',&quot;Paypal doesn't like your credit card number. Please try another.&quot;);
}

November 17th, 2008 / Tags: PHP, Symfony, code, tutorial / Trackback

Loading extra YAML config files in Symfony 1.1

At Dogster, we had a bunch of strings and settings that we wanted to keep out of our actions and place into their own YAML files instead of overloading the app.yml file. Here’s how I did it:

You can use this Filter to load the files we’ll setup in app.yml. Place this new PHP file at “symfony_project/apps/frontend/lib/addYmlFilter.class.php”.

<pre id="geshi_code">class addYmlFilter extends sfFilter
{
  public function execute($filterChain)
  {
    // Execute this filter only once
    if ($this-&gt;isFirstCall() &amp;&amp; is_array(sfConfig::get('app_load_yml_files')))
    {
      // Filters don't have direct access to the request and user objects.
      // You will need to use the context object to get them
      foreach(sfConfig::get('app_load_yml_files') as $file){
        @include(sfContext::getInstance()-&gt;getConfigCache()-&gt;checkConfig('config/'.$file.'.yml'));
      }
    }
    // Execute next filter
    $filterChain-&gt;execute();
  }
}

That filter takes care of all your caching and per-environment settings, the same as app.yml or the others in the config folder.

We will now setup four (4) new YAML files (config/paypal.yml, config/email.yml, config/flash.yml, config/forms.yml)

Place this in your app.yml file:

<pre id="geshi_code">load:
    yml_files:
        0: paypal
        1: email
        2: flash
        3: forms

Lastly, create a new YAML file “config/config_handlers.yml” with entries for each YAML file we would like to load:

<pre id="geshi_code">config/paypal.yml:
  class:    sfDefineEnvironmentConfigHandler
  param:
    prefix: paypal_
config/email.yml:
  class:    sfDefineEnvironmentConfigHandler
  param:
    prefix: email_
config/forms.yml:
  class:    sfDefineEnvironmentConfigHandler
  param:
    prefix: forms_
config/flash.yml:
  class:    sfDefineEnvironmentConfigHandler
  param:
    prefix: flash_

Here is some example content you might find within email.yml:

<pre id="geshi_code">all:
  admin: 'admin@example.com'

Once you load up Symfony, you should see all of your new config settings in the debug toolbar under “vars & config” > “SETTINGS”.

If you would like to place the new admin email setting within your code, you can now use sfConfig:

<pre id="geshi_code">echo sfConfig::get('email_admin');

Simple!

November 17th, 2008 / Tags: symfony, php, tutorial / Trackback


I just got this book for my birthday. It’s a beautiful book. I’ve read only a few entries and I’m already hooked. Let’s not forget to learn from those that came before us.

November 17th, 2008 / Tags: learning, book / Trackback

Next →