HH.
HH.

Reputation: 197

Set APPLICATION_ENV in Zend Framework 1.12

I just stated to get familiar with Zend Framework 1.12 and I don't understand how the dispatching of the application environment should work. In the Zend Framework index.php I can see:

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

When I var_dump(getenv('APPLICATION_ENV')) I get "bool(false)". So I really don't get it how Zend would know that it should use the development environment instead of the production environment. I would expected something like that:

defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? 'development' : 'production'));

Many thanks for your help.

Upvotes: 1

Views: 1314

Answers (1)

HH.
HH.

Reputation: 197

Ok. As it seems there are different approaches how to set the APPLICATION_ENV constant in ZF1. I decided to set the constant in the .htaccess file. (If you create a new Zend project with the Zend_Tools you will see that by default a .htaccess file will be created inside the folder application/public). Here I just added the first line and now I am able to call the preferred environment.

SetEnv APPLICATION_ENV development

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::$
RewriteRule ^(.*)$ - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

Reference: Keith Pope (Zend Framework 1.8 Web Application Development), page 15

Upvotes: 3

Related Questions