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

Tags: ,

October 5th, 2008, posted by alex

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';

Tags: , ,

October 3rd, 2008, posted by alex

Not working HTTPS queries with Curl

If you can work with usual http queries using PHP Curl, but have problems with https you can try to include this option:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

Tags: , ,

July 22nd, 2008, posted by Atuk

Converting openssh key from seahorse to putty

If you want to use your key generated in Seahorse in Putty you’ll have to convert it. The process is clear – make export of private key in Seahorse and import it to Puttygen. However one extra step is required – you have to delete everything before —–BEGIN DSA PRIVATE KEY—– mark. Otherwise Puttygen won’t recognise private key.

Tags:

May 31st, 2008, posted by alex

Finding matrix’s max or min element in MatLab

Function max(A) (or min(A)) return a row vector with maximum (minimum) elements from each column of matrix A. If you need to find largest or smallest element in the vhole matrix, you should use max() or min() function once again: max(max(A)) or min(min(A)).

Tags:

May 18th, 2008, posted by Atuk

Prototype.js formElmt.request() and non-valid HTML

Handy and pretty $('myform').request() can be easily broken if you have really broken HTML. For example:

<table>
<form id="myform">
  <input />
  <input />
  <tr><td></td></tr>
</table></form>

$('myform').serialize() will return empty string for such html. As a result you’ll have ajax request with no parameters, obviously not what you’ve expected. Fix html and everything will work.

Tags: , ,

May 16th, 2008, posted by alex

Add font to your system (Windows)

When you working with graphics, for example in Photoshop, you may need to use nonstandart fonts. To add new font you can copy font file to Windows/Fonts directory. You can access it using usual file manager or via Control Panel -> Fonts.

Tags: ,

May 13th, 2008, posted by Atuk

tty’s killed on Ubuntu Hardy Heron VPS

If you’ve upgraded your Ubuntu VPS to 8.04 check your syslog. It could happen that getty processes are being killed all the time:

May  2 06:28:54 vps_server init: tty3 main process (19690) terminated with status 1
May  2 06:28:54 vps_server init: tty3 main process ended, respawning
May  2 06:28:59 vps_server init: tty6 main process (19753) terminated with status 1
May  2 06:28:59 vps_server init: tty6 main process ended, respawning
May  2 06:29:00 vps_server init: tty5 main process (19764) terminated with status 1
May  2 06:29:00 vps_server init: tty5 main process ended, respawning
May  2 06:29:00 vps_server init: tty1 main process (19772) terminated with status 1
May  2 06:29:00 vps_server init: tty1 main process ended, respawning
May  2 06:29:02 vps_server init: tty4 main process (19891) terminated with status 1
May  2 06:29:02 vps_server init: tty4 main process ended, respawning
May  2 06:29:02 vps_server init: tty2 main process (19892) terminated with status 1
May  2 06:29:02 vps_server init: tty2 main process ended, respawning
...

To get rid of this (you don’t need terminals on remote machine) edit files /etc/event.d/tty1, /etc/event.d/tty2, etc and comment lines that causes respawning:

respawn
exec /sbin/getty 38400 tty1

Tags: , , ,

May 9th, 2008, posted by alex

Tracking deployed svn revision

Sometimes it’s useful to know which subversion revision is installed on your website.

I propose simple solution for this. Each time you or somebody update your website, run the command:

svnversion /path/to/your/working/copy > version && scp version login@domain.tld:./version

It will get global revision from your working copy and uploads a file to website, so you can check revision anytime just by opening http://domain.tld/version

Tags:

April 5th, 2008, posted by alex

Exclude WordPress admin from AWStats statistics

This is dead easy, in AWStats config set parameter

SkipFiles="REGEX[^\/wp-admin]"

All newly parsed statistics won’t include admin.

Tags: ,

April 2nd, 2008, posted by alex