【问题标题】:How to see the development logs in termail of zend framework 2?如何在zend framework 2的终端查看开发日志?
【发布时间】:2017-08-15 10:04:09
【问题描述】:

我熟悉 ROR 开发。但最近开始在 php zend 框架中工作。他们是一种在终端(在 linux 中)中查看开发日志的方式,与 ROR 一样吗?

RAILS_ENV=发展

铁轨

但在 Zend 中,它的终端命令

php -S 0.0.0.0:8080 public/index

在生产环境中生成日志。如何让它们开发更具体地监控代码。
在文档中它是这样的:

如果 ($_SERVER['APPLICATION_ENV'] == '开发') { 错误报告(E_ALL); ini_set("display_errors", 1); }

但在终端中显示错误消息为:

PHP 注意:未定义索引:APPLICATION_ENV in /var/www/html/skeleton/public/index.php 在第 7 行

有点累了,请指点出路,谢谢。

【问题讨论】:

  • 你使用的是哪个版本的zend框架?
  • 在这里很难说出你在问什么,但猜测你可能正在寻找这个 -> stackoverflow.com/questions/18098006/…
  • zend 版本 2.4.13
  • 您在终端窗口中看到的是 Web 服务器日志(其中将包括错误)。 Zend Framework 默认不做任何额外的日志记录。

标签: php ruby-on-rails zend-framework zend-framework2 zend-studio


【解决方案1】:

问题

文档假设您使用的是 Apache:

可选地,使用 Apache 时,您可以使用 VirtualHost 中的 APPLICATION_ENV 设置让 PHP 将其所有错误输出到浏览器。这在您的应用程序开发过程中很有用。

来源:the manual

第一个解决方案:定义APPLICATION_ENV

正如another question 中所讨论的,您应该能够使用以下命令运行定义了APPLICATION_ENV 的开发服务器:

APPLICATION_ENV=development php -S 0.0.0.0:8080 public public/index

第二种解决方案:使用 Apache

您可以简单地设置一个 Apache VirtualHost,如 the manual 中所述。将以下内容放入您的 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-servicemanagerFactoryInterface 的工厂创建的东西中启用开发模式。下面我介绍示例应用程序配置、工厂和服务:

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

<?php

// imports, namespace…

class ExampleService
{
    protected $dev;

    public function __construct(array $config)
    {
        $this->dev = isset($config['development']) && $config['development'] === true;
    }

    public function doSomething()
    {
        if ($this->dev) {
            // …
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-26
    • 2015-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多