Archive for October, 2008

symfony admin generator – populating create form from filters

symfony has basic CRUD-like admin generator, which allows you to create controls for filtering list results. Naturally, if you have filtered list and press ‘create’ button it would be nice to have new form with populated from filter form fields.

Here’s basic idea how to do it. In my example I have Work entity which has foreign key to Category entity. I have list of works filterable by category id.
To populate category id on work creation form you need to override generated action:

class worksActions extends autoworksActions
{
  public function executeEdit()
  {
  	parent::executeEdit();
  	if ($this->getRequestParameter('action') == 'create')
  	{
  		$filters = $this->getUser()->getAttributeHolder()->getAll('sf_admin/work/filters');
  		if (isset($filters['category_id']))
  			$this->work->setCategoryId($filters['category_id']);
  	}
  }
}

Look into admin generated actions if you want to more clearly understand why we need such code. It is located at cache/admin/dev/modules/autoWorks/actions/actions.class.php

Sunday, October 5th, 2008

Error in PayPal NVP ExpressCheckout with Zend Framework

If you are using classes from Zend Framework Laboratory for PayPal integration (which is somewhat unfinished) you probably will have an error when trying

Zend_Service_Paypal::setExpressCheckout();

The error has strange description ‘Security header is not valid’ and not listed in PayPal documentation.

To fix the error you’ll have to change line in Zend/Service/PayPal.php (in Laboratory tree)

const SERVICE_URI = 'https://api-3t.sandbox.paypal.com/nvp';

to

const SERVICE_URI = 'https://api-3t.paypal.com/nvp';

Friday, October 3rd, 2008