0
votes

Iam familiar with ROR development. But recently started working in php zend framework. Is their a way to see the development logs live in the terminal(in linux) same as ROR as.

RAILS_ENV=development

rails s

But In Zend the its terminal command

php -S 0.0.0.0:8080 public public/index

produce logs in production environment.How to get them development like to monitor the code more specifically.
In documentation it has it like:

if ($_SERVER['APPLICATION_ENV'] == 'development') { error_reporting(E_ALL); ini_set("display_errors", 1); }

But show error message in terminal as:

PHP Notice: Undefined index: APPLICATION_ENV in /var/www/html/skeleton/public/index.php on line 7

that's bit wearied please suggest a way out thanks.

1
which version of zend framework you are using?Gautam Rai
Difficult to to tell what you're asking here, but at a guess you're maybe looking for this -> stackoverflow.com/questions/18098006/…Crisp
zend version 2.4.13user8112782
What you see in the terminal window are the web server logs (which will include errors). Zend Framework does not do any additional logging by default.Tim Fountain

1 Answers

0
votes

The problem

The documentation assumes that you’re using Apache:

Optionally, when using Apache, you can use the APPLICATION_ENV setting in your VirtualHost to let PHP output all its errors to the browser. This can be useful during the development of your application.

Source: the manual.

First solution: define APPLICATION_ENV

As discussed in another question, you should be able to run your development server with defined APPLICATION_ENV using the following command:

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

Second solution: use Apache

You may simply setup an Apache VirtualHost as said in the manual. Put the following in your VirtualHost config:

<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>

And update your hosts:

127.0.0.1 zf2-tutorial.localhost localhost

Refer to the manual in case of problems.

Third solution: use zf-development-mode

I won’t guide you through installation of this package (here are some instructions), but I’ll present two solutions for checking (in your code) whether development mode is enabled.

First method: check if config/development.config.php exists

After enabling development mode, contents of config/development.config.php.dist should be copied to config/development.config.php. In your code, use the following to check if you’re in development mode:

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
}

Second method: inject application config

Let’s assume that you want to check if development mode is enabled in a controller/service or other thing that can be created by a factory implementing zend-servicemanager’s FactoryInterface. Below I present example application config, factory and service:

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) {
            // …
        }
    }
}