我正在尝试在这样的微应用程序中使用记录器(https://docs.phalconphp.com/en/3.2/logging):
<?php
// Load required namespaces
use Phalcon\DI\FactoryDefault;
// Initialize the application
include getcwd() . '/../app/bootstrap.php';
// Create a new di to share resources across the application
$di = new FactoryDefault();
// Register singleton instance of the loaded config object
$di->setShared('config', function() use ($config) {
return $config;
});
$config = null;
// Register singleton instance of the logger adapter
$di->setShared('logger', function() {
return Phalcon\Logger\Factory::load([
'name' => APP_DIR . 'storage/logs/' . date('d-m-Y') . '_logs.txt',
'adapter' => 'file'
]);
});
// Create our micro Phalcon application
$app = new Phalcon\Mvc\Micro();
$app->setDI($di);
// Base api end point page
$app->get('/', function() use ($di) {
include(APP_DIR . 'home.php');
});
// Post-process request request
$app->after(function() use ($di, $start)
{
// Log request
if ($di->get('config')->app->debug) {
$di->get('logger')->debug(sprintf("Processed request for %s in %f seconds.\r\n",
$_SERVER['REMOTE_ADDR'],
( microtime(true) - $start)));
}
});
// Global 404 error handler
$app->notFound(function() {
throw new Exception('File not found.');
});
// Register global exception handler
set_exception_handler(function($exception) use ($di)
{
// Log unhandled exception as an error
$logger = $di->get('logger');
$logger->begin();
$logger->error($exception->getMessage());
$logger->debug($exception->getFile() . ':' . $exception->getLine());
$logger->debug("StackTrace:\r\n" . $exception->getTraceAsString() . "\r\n");
$logger->commit();
});
// Start handling api requests
$app->handle();
当我访问应用程序基本终点页面(即http://app.local/
)时,我看到了我的&#34; home&#34;页面内容。
在日志中,我看到两个条目:
[Sat, 22 Jul 17 04:56:12 +0100][DEBUG] Processed request for 127.0.0.1 in 0.000000 seconds.
[Sat, 22 Jul 17 04:56:13 +0100][ERROR] File not found.
[Sat, 22 Jul 17 04:56:13 +0100][DEBUG] C:\xampp\htdocs\app.local\public\index.php:98
[Sat, 22 Jul 17 04:56:13 +0100][DEBUG] StackTrace:
#0 [internal function]: {closure}()
#1 C:\xampp\htdocs\app.local\public\index.php(114): Phalcon\Mvc\Micro->handle()
#2 {main}
触发404找不到的是什么?
我在本地开发环境中使用Apache 2 + PHP 5.6。以下是我的.htaccess
文件的内容:
C:\ XAMPP \ htdocs中\ app.local \ htaccess的
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
C:\ XAMPP \ htdocs中\ app.local \公共\ htaccess的
AddDefaultCharset UTF-8
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
Apache的vhost DocumentRoot
设置为C:\xampp\htdocs\app.local