RSS - Latest postsThinkRobot

6Mar
2010

Multiple changes and a delete on same object in doctrine

If you want to make several different changes to a doctrine record object you might find yourself slightly puzzled when it comes to deleting related objects.

$user['Address']->delete();
$user['Address']->state(Doctrine_Record::STATE_LOCKED);
(...)
$user->save();

It seems that unless you set the state the save later on still sees an initialized (though empty!) relation.

Categories:

16Dec
2009

Zend_Date time part and GMT

If you live in the UK you might have a surprise waiting in store for you if you use Zend_Date for the time part only. For a while I even thought this was a bug, however digging deeper has shown that actually it’s Zend_Date that is right, in a way at least.

When setting a time before 1972 – this is 1970 and 1971 the time part will not be shifted in the UK locale as DST was only introduced in 1972!

This means if you are only calculating times and need the appropriate time adjustment you will need to set a date as no date part in Zend_Date means 1st Jan 1970.

Categories:

15Dec
2009

PHPUnit & Selenium – screenshot path problem

PHPUnit_Framework_Exception: Response from Selenium RC server for testComplete().
ERROR: Command execution failure. Please search the forum at http://clearspace.openqa.org for error details from the log window.
The error message is: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsILocalFile.initWithPath]

Setting up Selenium RC server together with PHPUnit has proven surprisingly easy… Well most of it. Every now and then as a beginner you might run into monster errors like the one above. No fear, what Selenium is trying to tell you is just that your path is wrong.

For me it happened when trying to setup the error screenshot variables:

protected $captureScreenshotOnFailure = TRUE;
protected $screenshotPath = '/var/www/localhost/htdocs/screenshots';
protected $screenshotUrl = 'http://localhost/screenshots';

In case you wonder the path relates to the browser’s host not the Selenium RC host (if they are different), In my case the browsers are run on a windows box, with the Selenium RC setup on a Linux machine. Thus the error about the inapropriate $screenshotPath.

Categories:

30Jul
2009

Autloading modular forms & models in Zend Framework 1.8

It’s not really obvious with the error messages you get, but using a thing like Form_Login does not work out of the box with a modular structure. Which is slightly surprising considering that it’s inside the default module.

I have found examples like the second one below, but no one mentions that you actually declare the default namespace too for everything to work.

$autoloader = new Zend_Application_Module_Autoloader(array(
	'namespace' => '',
	'basePath'  => APPLICATION_PATH .'/modules/default',
	'resourceTypes' => array (
		'form' => array(
		'path' => 'forms',
		'namespace' => 'Form',
    ),
	'model' => array(
		'path' => 'models',
		'namespace' => 'Model',
    	),
    )
));

$autoloader = new Zend_Application_Module_Autoloader(array(
	'namespace' => 'Admin_',
	'basePath'  => APPLICATION_PATH .'/modules/admin',
	'resourceTypes' => array (
		'form' => array(
		'path' => 'forms',
		'namespace' => 'Form',
    ),
	'model' => array(
		'path' => 'models',
		'namespace' => 'Model',
    	),
    )
));

Categories:

29Jul
2009

Redirect in controller plugin – Zend Framework 1.8

If you need to redirect while inside a controller plugin, for example in preDispatch() here is a quick way to do it:

$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->gotoUrl('/login/');

Categories: