Zend Framework application.ini cheat sheet

Sometimes it’s a real pain to put the right stuff in your Zend configuration to get your application working good almost automatically. Having the right configuration in your application.ini will save you from having to create and configure various instances by yourself e.g. $log = new Zend_Log(array(…)); Zend Framework has the so called “resource plugins”, that can be configured and initialized by few lines in the application.ini file.

These configuration settings have been tested on Zend 1.x

Database configuration:

resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "asdwqe"
resources.db.params.dbname = "my_database"
resources.db.params.charset = "utf8"
resources.db.isDefaultTableAdapter = true
resources.db.defaultMetadataCache = "database"

The last option “defaultMetadataCache” defines the name of the cache manager instance, that should be used to cache database related stuff, like table descriptions, field lists, etc.
To get the database adapter anywhere in your project:

$bootstrap = Zend_Controller_Front::getInstance()->getParam("bootstrap");
$db = $bootstrap->getPluginResource('db')->getDbAdapter();



resources.cachemanager.database.frontend.name = Core
resources.cachemanager.database.frontend.customFrontendNaming = false
resources.cachemanager.database.frontend.options.lifetime = 600
resources.cachemanager.database.frontend.options.automatic_serialization = true
resources.cachemanager.database.backend.name = File
resources.cachemanager.database.backend.customBackendNaming = false
resources.cachemanager.database.backend.options.cache_dir = APPLICATION_PATH "/temp/cache"

The “database” key in the configuration defines the name of the cache instance in the cache manager resource plugin. You can define as much cache instances as you wish, with different configurations, like backend engines and etc.
To get the cache in the controller use:


To get the cache object anywhere:

$bootstrap = Zend_Controller_Front::getInstance()->getParam("bootstrap");
$cache = $bootstrap->getPluginResource("cachemanager")->getCacheManager()->getCache("database");

Often during development it is useful to enable logging on the cachemanager to see what is being cached:

resources.cachemanager.database.frontend.options.logging = "true"


Saving sessions as files:

resources.session.save_path = APPLICATION_PATH "/temp/session"
resources.session.use_only_cookies = true
resources.session.remember_me_seconds = 864000

When you create new Zend_Session_Namespace(); all data will now be stored in APPLICATION_PATH.”/temp/session”
When developing a facebook application, make sure you create an instance of Zend_Session_Namespace() before Facebook().

To configure logging to a file:

resources.log.stream.writerName = "Stream"
resources.log.stream.writerParams.stream = APPLICATION_PATH "/temp/logs/app.log"
resources.log.stream.writerParams.mode = "a"
resources.log.stream.filterName = "Priority"
resources.log.stream.filterParams.priority = 4</pre>
In development, you can use Firebug (<a href="http://www.firephp.org/" target="_blank">Firephp</a> extension) for quick reference of what is going on in your application:
<pre style="background-color: #f3f3f3;">resources.log.browser.writerName = "Firebug"
resources.log.browser.filterParams.priority = 7

The “browser” key in the configuration defines the name of the logger in the log resource plugin. You may have as much loggers as you want.
Now to log from the controller just get the preconfigured resource:

$this->bootstrap->getResource('Log')->log($message, $severity, array('firebugLabel' => $label));


Configuring mail:

resources.mail.transport.type = sendmail
resources.mail.transport.register = true
resources.mail.defaultFrom.email = "admin@example.com"
resources.mail.defaultFrom.name = "From name"
resources.mail.defaultReplyTo.email = "admin@example.com"
resources.mail.defaultReplyTo.name = "Reply name"

To send e-mails you can now follow the official guide.

To set php ini values:

phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
phpSettings.magic_quotes_gpc = 0
phpSettings.date.timezone = "America/New_York"


Base url:

When your project is running from a directory (example.com/path/to/project) you’ll need to set baseUrl in the front controller, so that routing, redirects and a whole bunch of other stuff continues working. This can be done from the application.ini:

resources.frontController.baseUrl = "/"

After doing this, you can use baseUrl view helper to generate urls around your application:

echo $this->baseUrl("/users");

This is just a cheat sheet to get you started on the most common configuration settings. If you need a more detailed information and explanation you can check out the official guide on resource plugins.

Leave a Reply

Your email address will not be published. Required fields are marked *