我想知道为什么当我将我的 ZF2 项目克隆到本地机器上进行一些测试时它完全停止工作。
在我的本地机器上,我有两个子文件夹,一个包含 cakePHP 项目,另一个包含我克隆的 ZF2。
cakePHP 项目工作正常,因为它先在那里,但是 ZF2,当我尝试访问公用文件夹时,它打印我:
{"error":"Something went wrong"}
一个非常普遍的错误...我不知道发生了什么。
我已经尝试了一些一般的调试尝试,比如
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
完全没有成功,我还检查了 .htaccess RewriteBase 指令以匹配我的子文件夹,数据库配置也已完成。
我在项目中做了一些研究,显示错误的文件是module/RestfulV2_2/Module.php
(阅读我发现的README.md
是 ZF2 Restful Module Skeleton 的一部分):
/**
* @param MvcEvent $e
* @return null|\Zend\Http\PhpEnvironment\Response
*/
public function errorProcess(MvcEvent $e)
{
/** @var \Zend\Di\Di $di */
$di = $e->getApplication()->getServiceManager()->get('di');
$eventParams = $e->getParams();
/** @var array $configuration */
$configuration = $e->getApplication()->getConfig();
$vars = array();
if (isset($eventParams['exception'])) {
/** @var \Exception $exception */
$exception = $eventParams['exception'];
if ($configuration['errors']['show_exceptions']['message']) {
$vars['error-message'] = $exception->getMessage();
}
if ($configuration['errors']['show_exceptions']['trace']) {
$vars['error-trace'] = $exception->getTrace();
}
}
if (empty($vars)) {
$vars['error'] = 'Something went wrong';
}
/** @var PostProcessor\AbstractPostProcessor $postProcessor */
$postProcessor = $di->get(
$configuration['errors']['post_processor'],
array('vars' => $vars, 'response' => $e->getResponse())
);
$postProcessor->process();
if (
$eventParams['error'] === \Zend\Mvc\Application::ERROR_CONTROLLER_NOT_FOUND ||
$eventParams['error'] === \Zend\Mvc\Application::ERROR_ROUTER_NO_MATCH
) {
$e->getResponse()->setStatusCode(\Zend\Http\PhpEnvironment\Response::STATUS_CODE_501);
} else {
$e->getResponse()->setStatusCode(\Zend\Http\PhpEnvironment\Response::STATUS_CODE_500);
}
$e->stopPropagation();
return $postProcessor->getResponse();
}
在我的 index.php 中调用错误的行是:
Zend\Mvc\Application::init(require 'config/application.config.php')- run();
我发现以某种方式调用错误函数的唯一一行是我的 modele.php
中的这一行:
$sharedEvents->attach('Zend\Mvc\Application', MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'errorProcess'), 999);
你能帮我解决这个问题吗?我对 ZF2 没有经验,但我知道使用 cakePHP 使其工作需要清除缓存文件夹。 ZF2有没有类似的流程?我应该虚拟化两台服务器以避免冲突吗?
提前谢谢你。
编辑:我已经制作了虚拟主机以避免我的两个框架之间发生任何可能的冲突,但错误输出仍然相同。
EDIT2:这是我的 application.config.php 文件:
return array(
// This should be an array of module namespaces used in the application.
'modules' => array(
'Restful',
'MvlabsSnappy',
'Qrcode',
'Application',
'RestfulV2',
'RestfulV2_2'
),
// These are various options for the listeners attached to the ModuleManager
'module_listener_options' => array(
// This should be an array of paths in which modules reside.
// If a string key is provided, the listener will consider that a module
// namespace, the value of that key the specific path to that module's
// Module class.
'module_paths' => array(
'./module',
'./vendor',
),
// An array of paths from which to glob configuration files after
// modules are loaded. These effectively override configuration
// provided by modules themselves. Paths may use GLOB_BRACE notation.
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
// Whether or not to enable a configuration cache.
// If enabled, the merged configuration will be cached and used in
// subsequent requests.
//'config_cache_enabled' => $booleanValue,
// The key used to create the configuration cache file name.
//'config_cache_key' => $stringKey,
// Whether or not to enable a module class map cache.
// If enabled, creates a module class map cache which will be used
// by in future requests, to reduce the autoloading process.
//'module_map_cache_enabled' => $booleanValue,
// The key used to create the class map cache file name.
//'module_map_cache_key' => $stringKey,
// The path in which to cache merged configuration.
//'cache_dir' => $stringPath,
// Whether or not to enable modules dependency checking.
// Enabled by default, prevents usage of modules that depend on other modules
// that weren't loaded.
// 'check_dependencies' => true,
),
// Used to create an own service manager. May contain one or more child arrays.
//'service_listener_options' => array(
// array(
// 'service_manager' => $stringServiceManagerName,
// 'config_key' => $stringConfigKey,
// 'interface' => $stringOptionalInterface,
// 'method' => $stringRequiredMethodName,
// ),
// )
// Initial configuration with which to seed the ServiceManager.
// Should be compatible with Zend\ServiceManager\Config.
// 'service_manager' => array(),
);
最佳答案
首先,我会打开 index.php 或任何用作初始文件 (DirectoryIndex) 的文件,并暂时将其全部内容完全替换为非常基本和简单的内容,例如这两行:
<?php
phpinfo();
然后确保它在那之后开始工作 - 使用仅显示您的 php 配置的简单代码。所以我们会发现在服务器配置、权限等方面没有错误,并且没有任何东西阻止您的脚本运行。
然后我会在您的旧项目位置做同样的事情,只是为了从那个地方也获取 phpinfo() 并浪费一些时间来比较它们。也许您错过了一些重要的东西,现在您会看到它。
如果没有 - 如果您的项目使用任何数据库,下一步我将检查您的数据库连接...还有一些非常简单的命令,如连接、绑定(bind)...。
最后我会尝试从一开始就一步步恢复原来的项目内容,看哪一步会失败。可能没有任何输出并不重要 - 你可以输入 echo __LINE__ . ' works!<br/>';
在 block 之间,所以你的 index.php 看起来像:
<?php
// original code block 1
echo __LINE__ . ' works!<br/>';
// original code block 2
echo __LINE__ . ' works!<br/>';
您会在浏览器中看到失败的地方。
这是对我的调试原则的非常基本的描述,但希望它能有所帮助。
关于php - ZF2 项目在克隆到本地服务器时停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36763639/