During the creation of a web application, on many occasions it is necessary to do something that requires the use of an external library.

If you happen to be building your web application using symfony, it is possible to use parts of the Zend Framework (and other frameworks and libraries) independently. This enables a whole new world of features with no preset limits.

At ServerGrove we use symfony for many of our projects, and also use Zend Framework since it provides many great components. This is why, we are always up to date on both frameworks and you will get excellent technical support when hosting your framework based sites with us.

So, as an example, you can use Zend_Mail to send emails from symfony. Some other components that are very useful in the symfony world are:

– Zend_Currency
– Zend_Mime
– Zend_Ldap
– Zend_Http
– Zend_OpenId
– Zend_Pdf

And the list goes on.

But going back to the Zend_Mail example, first, we need to tell symfony where to find the Zend Framework library.

All our servers here at ServerGrove come with not only symfony pre-installed but also we have all latests Zend Framework releases. It will be located at /usr/local/php/Zend. This will always be the latest stable version. If you need to use a specific version of the framework (to avoid possible future compatibility issues) you can also link to a specific version, for example /usr/local/php/ZendFramework-1.7.0/library

So, we need to modify the file config/ProjectConfiguration.class.php so we can use the autoloader provided by ZF, it should look like this:


// config/ProjectConfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration
{
static protected $zendLoaded = false;

static public function registerZend()
{
if (self::$zendLoaded)
{
return;
}

$zflib = '/usr/local/php/Zend';

set_include_path($zflib.PATH_SEPARATOR.get_include_path());
require_once $zflib.'/Loader.php';
Zend_Loader::registerAutoload();
self::$zendLoaded = true;
}

// ...
}

Then when we need to send the email, usually in an action, this is what we do:


ProjectConfigation::registerZend();
$mail = new Zend_Mail();
$mail->setBodyText('Message body');
$mail->setFrom('me@example.com', 'My name');
$mail->addTo($recipientEmail);
$mail->setSubject('Subject');
$mail->send();

That’s it. Could not be simpler! As we said, this opens many possibilites by using external libraries and avoids reinventing the wheel. By using the set of libraries and frameworks we provide on ServerGrove, it has never been easier to develop and run powerful and professional websites.