在Zend Framework 1.12中设置APPLICATION_ENV

时间:2015-02-28 23:26:56

标签: zend-framework

我刚刚说过熟悉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'));

非常感谢你的帮助。

1 个答案:

答案 0 :(得分:2)

确定。因为看起来有不同的方法如何在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}::$1 ^(/.+)(.+)::$
RewriteRule ^(.*)$ - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

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