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.
The documentation assumes that you're using Apache:
Optionally, when using Apache , you can use the
APPLICATION_ENV
setting in yourVirtualHost
to let PHP output all its errors to the browser. This can be useful during the development of your application.
Source: the manual .
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
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.
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.
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
}
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) {
// …
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.