在我的本地机器上,我有两个子文件夹,一个带有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(); }
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(),);
解决方法
<?PHP PHPinfo();
然后确保它在那之后开始工作 – 使用那个只显示你的PHP配置的简单代码.因此,我们将发现服务器配置,权限等没有错误,并且没有任何东西阻止您的脚本运行.
然后我会在您的旧项目位置执行相同操作,以便从该位置获取PHPinfo()并浪费一些时间来尝试比较它们.也许你错过了重要的事情,现在你会看到它.
如果没有 – 下一步我会检查你的数据库连接,如果你的项目使用任何数据库……还有一些非常简单的命令,如connect,bind,….
最后,我将尝试从开始逐步恢复原始项目内容,并查看它将失败的步骤.没有任何输出也没关系 – 你可以把echo __LINE__. ‘有效!< br />‘;在块之间,所以你的index.PHP看起来像:
<?PHP // original code block 1 echo __LINE__ . ' works!<br/>'; // original code block 2 echo __LINE__ . ' works!<br/>';
你会在浏览器中看到它失败的地方.
这是我的调试主体的基本描述,但希望它会有所帮助.