在 Zend Framework 1.12 中设置 APPLICATION_ENV

Set APPLICATION_ENV in Zend Framework 1.12

我只是说要熟悉Zend Framework 1.12,我不明白应用程序环境的调度应该如何工作。在 Zend Framework index.php 我可以看到:

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

当我 var_dump(getenv('APPLICATION_ENV')) 我得到 "bool(false)"。所以我真的不明白 Zend 怎么会知道它应该使用开发环境而不是生产环境。我会期待这样的事情:

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

非常感谢您的帮助。

好的。似乎有不同的方法如何在 ZF1 中设置 APPLICATION_ENV 常量。我决定在 .htaccess 文件中设置常量。 (如果您使用 Zend_Tools 创建一个新的 Zend 项目,您会看到默认情况下会在文件夹 application/public 中创建一个 .htaccess 文件)。在这里我只是添加了第一行,现在我可以调用首选环境了。

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}:: ^(/.+)(.+)::$
RewriteRule ^(.*)$ - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

参考资料:Keith Pope(Zend Framework 1.8 Web 应用程序开发),第 15 页