我熟悉ROR开发。但最近开始在php zend框架中工作。他们是否可以在终端(在Linux中)查看开发日志,与ROR一样。
RAILS_ENV =发展
rails s
但是在Zend中它的终端命令
php -S 0.0.0.0:8080 public public / index
在生产环境中生成日志。如何让他们开发更具体地监控代码 在文档中它具有如下:
if($ _SERVER [' APPLICATION_ENV'] ==' development'){ 使用error_reporting(E_ALL); ini_set(" display_errors",1); }
但是在终端中显示错误消息:
PHP注意:未定义的索引:APPLICATION_ENV in 第7行的/var/www/html/skeleton/public/index.php
有点疲惫请建议一个出路谢谢。
答案 0 :(得分:0)
文档假定您使用的是Apache:
(可选)使用Apache 时,您可以使用
APPLICATION_ENV
中的VirtualHost
设置让PHP将所有错误输出到浏览器。这在您的应用程序开发过程中非常有用。
来源:the manual。
APPLICATION_ENV
如another question中所述,您应该能够使用以下命令运行定义为APPLICATION_ENV
的开发服务器:
APPLICATION_ENV=development php -S 0.0.0.0:8080 public public/index
您可以像the manual中所述设置Apache VirtualHost
。将以下内容放入VirtualHost
配置:
<VirtualHost *:80>
ServerName zf2-tutorial.localhost
DocumentRoot /path/to/zf2-tutorial/public
SetEnv APPLICATION_ENV "development"
<Directory /path/to/zf2-tutorial/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
并更新您的hosts
:
127.0.0.1 zf2-tutorial.localhost localhost
如果出现问题,请参阅the manual。
zf-development-mode
我不会指导您完成this package(here are some instructions)的安装,但我会提供两种解决方案来检查(在您的代码中)是否启用了开发模式。
config/development.config.php
是否存在启用开发模式后,config/development.config.php.dist
的内容应复制到config/development.config.php
。在您的代码中,使用以下内容检查您是否处于开发模式:
if (file_exists('config/development.config.php')) {
// in default skeleton application. You may have to play with
// __DIR__ if you’ve modified your public/index.php
}
假设您要检查控制器/服务中是否启用了开发模式,或者是否可以由实施zend-servicemanager
的{{1}}的工厂创建的其他内容。下面我展示示例应用程序配置,工厂和服务:
FactoryInterface
config/development.config.php.dist
<?php
return [
'development' => true
];
Application\Service\Factory\ExampleServiceFactory
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
return new ExampleService($container->get('Config'));
}
Application\Service\ExampleService