php - How to see the development logs in termail of zend framework 2? -
iam familiar ror development. started working in php zend framework. way see development logs live in terminal(in linux) same ror as.
rails_env=development
rails s
but in zend terminal command
php -s 0.0.0.0:8080 public public/index
produce logs in production environment.how them development monitor code more specifically.
in documentation has 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 way out thanks.
the problem
the documentation assumes you’re using apache:
optionally, when using apache, can use
application_env
setting invirtualhost
let php output errors browser. can useful during development of application.
source: the manual.
first solution: define application_env
as discussed in another question, should able run development server defined application_env
using following command:
application_env=development php -s 0.0.0.0:8080 public public/index
second solution: use apache
you may setup apache virtualhost
said in the manual. put following in 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 require granted </directory> </virtualhost>
and update hosts
:
127.0.0.1 zf2-tutorial.localhost localhost
refer the manual in case of problems.
third solution: use zf-development-mode
i won’t guide through installation of this package (here instructions), i’ll present 2 solutions checking (in code) whether development mode enabled.
first method: check if config/development.config.php
exists
after enabling development mode, contents of config/development.config.php.dist
should copied config/development.config.php
. in code, use following check if you’re in development mode:
if (file_exists('config/development.config.php')) { // in default skeleton application. may have play // __dir__ if you’ve modified public/index.php }
second method: inject application config
let’s assume want check if development mode enabled in controller/service or other thing can created factory implementing zend-servicemanager
’s factoryinterface
. below present example application config, factory , 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) { // … } } }
Comments
Post a Comment