当克隆到本地服务器

时间:2016-04-21 08:13:00

标签: php zend-framework2

我想知道为什么当我将我的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(),
);

2 个答案:

答案 0 :(得分:2)

首先,我会打开index.php或任何用作初始文件(DirectoryIndex)的内容,并暂时完全用一些基础和简单的内容替换整个内容,例如这两行:

<?php
  phpinfo();

然后确保它在那之后开始工作 - 使用那个只显示你的php配置的简单代码。因此,我们发现服务器配置,权限等没有任何错误,并且没有任何东西阻止您的脚本运行。

然后我会在您的旧项目位置做同样的事情,只是为了从那个地方获取phpinfo()并浪费一些时间来尝试比较它们。也许你错过了一些重要的东西,你现在就会看到它。

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

最后,我尝试从一开始就逐步恢复原始项目内容,并查看它将失败的步骤。可能没有任何输出并不重要 - 您可以在块之间放置echo __LINE__ . ' works!<br/>';,因此您的index.php将如下所示:

<?php

// original code block 1

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

// original code block 2

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

您将在浏览器中看到它失败。

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

答案 1 :(得分:1)

错误可能是任何事情。但是,假设已执行发布的代码,它将在没有正确配置的情况下抑制错误消息。

尝试将以下配置添加到public double randDouble(double bound1, double bound2) { //make sure bound2> bound1 double min = Math.min(bound1, bound2); double max = Math.max(bound1, bound2); //math.random gives random number from 0 to 1 return min + (Math.random() * (max - min)); }

randDouble(1,100)
//example result:
//56.736451234

如果抛出异常并且该侦听器正在捕获它,则local.config.php是您应该调试的。