zendamf无法在服务器中加载类

时间:2013-09-30 04:25:58

标签: php zend-amf

我正在开发一个flex php项目,我正在使用zendamf传递remotemessages。在我的本地主机上一切正常,但是当我上传zendframework以及服务时,似乎gateway.php无法在服务器上找到我的服务。如果我手动添加类,一切都恢复正常。 我的gateway.php是:

<?php
ini_set("display_errors", 1);
$dir = dirname(__FILE__);

$webroot = $_SERVER['DOCUMENT_ROOT'];
$configfile = "$dir/amf_config.ini";

//default zend install directory
$zenddir = $webroot. '/ZendFramework/library';

//Load ini file and locate zend directory
if(file_exists($configfile)) {
    $arr=parse_ini_file($configfile,true);
    if(isset($arr['zend']['webroot'])){
        $webroot = $arr['zend']['webroot'];
        $zenddir = $webroot. '/ZendFramework/library';
    }
    if(isset($arr['zend']['zend_path'])){
        $zenddir = $arr['zend']['zend_path'];
    }
}


// Setup include path
    //add zend directory to include path
set_include_path(get_include_path().PATH_SEPARATOR.$zenddir);
// Initialize Zend Framework loader

require_once 'Zend/Loader/Autoloader.php';

Zend_Loader_Autoloader::getInstance();
// Load configuration
$default_config = new Zend_Config(array("production" => false), true);
$default_config->merge(new Zend_Config_Ini($configfile, 'zendamf'));
$default_config->setReadOnly();
$amf = $default_config->amf;


// Store configuration in the registry
Zend_Registry::set("amf-config", $amf);


// Initialize AMF Server
$server = new Zend_Amf_Server();

$server->setProduction($amf->production);

if(isset($amf->directories)) {
    $dirs = $amf->directories->toArray();
    foreach($dirs as $dir) {

        // get the first character of the path. 
        // If it does not start with slash then it implies that the path is relative to webroot. Else it will be treated as absolute path
        $length = strlen($dir);
        $firstChar = $dir;
        if($length >= 1)
            $firstChar = $dir[0];

        if($firstChar != "/"){
            // if the directory is ./ path then we add the webroot only.
            if($dir == "./"){               
                $server->addDirectory($webroot);
            }else{
                $tempPath = $webroot . "/" . $dir;
                $server->addDirectory($tempPath);
            }       
        }
        else{
            $server->addDirectory($dir);
        }
    }
}
// Initialize introspector for non-production
if(!$amf->production) {
    $server->setClass('Zend_Amf_Adobe_Introspector', '', array("config" => $default_config, "server" => $server));
    $server->setClass('Zend_Amf_Adobe_DbInspector', '', array("config" => $default_config, "server" => $server));
}


// Handle request
echo $server->handle();

如果我添加这两行来手动设置类,那么它可以正常工作

require_once 'services/serviceTest.php';
$server->setClass("serviceTest");

最令人困惑的部分是默认的gateway.php在localhost中工作正常。任何人都可以帮我如何在服务器中自动加载类?

1 个答案:

答案 0 :(得分:0)

解决了!!! 似乎zendamf框架的PluginLoader.php试图找到相应的服务,但不是通过类名。 例如: 我的班级名称是“serviceTest” 所以插件加载器试图找出名为“ServiceTest.php”的服务 我更改了php文件名(使第一个字符为大写)并且它可以工作!!!

我希望它可以帮助那些像我一样陷入困境的人 :)