php – 当克隆到本地服务器时,ZF2项目停止工作

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 当克隆到本地服务器时,ZF2项目停止工作脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我想知道为什么当我将我的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()并浪费一些时间来尝试比较它们.也许你错过了重要的事情,现在你会看到它.

如果没有 – 下一步我会检查你的数据库连接,如果你的项目使用任何数据库……还有一些非常简单的命令,如connect,bind,….

最后,我将尝试从开始逐步恢复原始项目内容,并查看它将失败的步骤.没有任何输出也没关系 – 你可以把echo __LINE__. ‘有效!< br />‘;在块之间,所以你的index.PHP看起来像:

<?PHP

// original code block 1

  echo __LINE__ . ' works!<br/>';

// original code block 2

  echo __LINE__ . ' works!<br/>';

你会在浏览器中看到它失败的地方.

这是我的调试主体的基本描述,但希望它会有所帮助.

脚本宝典总结

以上是脚本宝典为你收集整理的php – 当克隆到本地服务器时,ZF2项目停止工作全部内容,希望文章能够帮你解决php – 当克隆到本地服务器时,ZF2项目停止工作所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。