Category Archives : Zend Framework

Nginx config for Zend Framework 1

My server is running Ubuntu with Nginx and php5-fpm. I wasn’t able to find a quick drop in config for my zend framework 1 project so I wanted to share what I was able to get working. Also notice nginx is listening to tcp port 9000 instead of the default unix socket.

server {
  listen 80;
  root /var/www/mysite/public_html;
  location / {
   try_files $uri $uri/ /index.php$is_args$args;
   index index.php;
  # PHP scripts will be forwarded to fastcgi processess.
  location ~ \.php$ {
   include /etc/nginx/fastcgi_params;
    fastcgi_index  index.php;

Zend_Cache_Core is missing the setCacheDir method

This seems to be troubling a lot of people, so after debugging Zend’s code, I’ll post the solution on how to change the cache directory of zend_cache.

I’m using the below code in my zend framework bootstrap to setup Zend_Cache for caching to files.

$frontend= array('lifetime' => 7200,
				 'automatic_serialization' => true);
$backend= array('cache_dir' => DIR_CACHE);
$cache = Zend_Cache::factory('core',
//assign to registry                        
$registry     = Zend_Registry::getInstance();
$registry->cache = $cache;

I need to be able to override the cache directory at a later time and when I’m ready to use the cache in the application, I reference this Zend_Cache like below, which returns an object of Zend_Cache_Core, which you cannot call setCacheDir() on. We must first get the backend component, then call the method as below.

$cache = Zend_Registry::get('cache');
//set the new cache directory

How to insert an event onto secondary calendar using the google calendar api 2

With Zend Framework, I used their Gdata library to interface with the Google api. My application will be managing three separate calendars with the same Google account. Zend’s documentation does not tell you how to add an event to a calendar other than the default primary calendar. It’s not obvious with Google’s own API documentation either.

After some digging, I found the Zend_Gdata_Calendar::insertEvent() method accept a second optional parameter called $uri. There aren’t any comments or hints as to what this uri is for, but it is actually where you specify the calendar you’d like your event added to. How do you get the uri for your calendars? You need to query the api to get the information like below. Set your Google calendar login info in the below code and it will print your calendar uri’s to the screen. Use these uri’s as the second parameter to insertEvent().

$client = Zend_Gdata_ClientLogin::getHttpClient(GOOGLE_CALENDAR_USERNAME, GOOGLE_CALENDAR_PASSWORD, Zend_Gdata_Calendar::AUTH_SERVICE_NAME);
// Create an instance of the Calendar service
$service = new Zend_Gdata_Calendar($client);
try {
	$listFeed= $service->getCalendarListFeed();
} catch (Zend_Gdata_App_Exception $e) {
	echo "Error: " . $e->getMessage();
foreach ($listFeed as $calendar) {
	echo '<br>calendar title: ' . $calendar->title->text;
	echo '<br>calendar uri: ' . $calendar->content->src;

Zend_Form Recaptcha doesn’t work with SSL 1

I was able to get a recaptcha working on my Zend Framwork application, but as soon as I added the “‘ssl’ => true” to my zend_form, the captcha disappeared. Here is the code used in zend_form:

$this->addElement('captcha', 'captcha', array(
	'label' => 'Please Type:',
	'required' => true,
	'captcha' => array(
		'captcha' => 'reCaptcha',
		'ssl'	=> true

The reason ssl didn’t work with recaptcha is because the secure URL was out of date in my zend framework library. To update, open /Zend/Service/ReCaptcha.php and update the server constants at the top to

 * URI to the regular API
 * @var string
const API_SERVER = '';
 * URI to the secure API
 * @var string
 * URI to the verify server
 * @var string
const VERIFY_SERVER = '';