Database unit testing can sometimes be a bit tricky to get working well, especially when using Doctrine. In an earlier post I showed how I overcame caching issues I had experienced when using Doctrine with PHPUnit. This post builds upon…
A quick one I recently learned about, Zend_Validate_Interface::isValid allows an optional second argument in addition to the required value parameter: public function isValid($value, $context = null) { Zend_Debug::dump($context); die; } When used as a form element validator, $context will contain…
Running Zend Framework as a script can obviously be useful in many circumstances. These are the steps I take to get up and running on the command line. Modify index.php This is a modified version of the usual /public/index.php. In…
I mainly develop on Windows, and I have recently received an error a couple of times after deploying my Zend Framework applications to Linux boxes: Fatal error: Uncaught exception ‘Zend_Loader_PluginLoader_Exception’ with message ‘Plugin by name ‘MyPlugin’ was not found in…
Doctrine doesn’t seem to have an inbuilt mechanism for checking for duplicate entries; one solution thrown around the web is to simply try catch the PDOException code 23000. Here is a solution I use, which makes use of the MetadataFactory…
I wanted to exclude a certain document ID from within Sphinx: sql_query = \ SELECT u.id AS u_id FROM users u sql_attr_uint = u_id and then in PHP: $sphinxClient->addFilter(’u_id’, $userId, true); As you are unable to filter directly on…
Sphinx doesn’t support filtering by strings as attributes (yet), so here are two options you can use to get around this limitation… Querying by Attribute This option requires you to define a text field in your Sphinx config and reference…
I came across the popular jQuery File Upload plugin while looking for a simple to use and extensible file upload solution to integrate into a Zend Framework project. It can be a bit tricky to get this plugin working, so…
I needed a simple way to validate user-inputted XML with Zend_Form, so decided to write a simple validator: The validator simply loads the XML from the form element value with DomDocument. By forcing libxml to allow us to retrieve error…
A quick script I use to truncate all entities registered in Doctrine: $connection = $entityManager->getConnection(); $schemaManager = $connection->getSchemaManager(); $tables = $schemaManager->listTables(); $query = ”; foreach($tables as $table) { $name = $table->getName(); $query .= ‘TRUNCATE ‘ . $name . ‘;’;…