在 php 中使用 zend 框架添加自定义类型


Add custom type with zend framework in php?

我无法使用 zend 框架添加新类型。我试过这个

$server = new Zend_Soap_Server('http://localhost/CycleProphet/amember/ws/index/wsdl');
$server->addComplexType('AMemberUser');
class AMemberUser
{
    public $UserId;
    public $FirstName;
    public $LastName;
}      

类型已添加,但它为空。我在 http://framework.zend.com/manual/en/zend.soap.wsdl.html#zend.soap.wsdl.types.add_complex 使用这篇文章,但它对我没有帮助。

在您发表评论后,我决定重写我的答案,并为您提供一些使用 wsdl 的解决方案:

<?php
require_once('Zend/Soap/Client.php');
require_once('Zend/Soap/Server.php');
require_once('Zend/Soap/Wsdl.php');
require_once('Zend/Soap/AutoDiscover.php');
class SoapController extends AppController 
{    
    public function zendclientAction()
    {
        $_client = new Zend_Soap_Client('http://localhost/php5_testapp/soap/zendserver?wsdl');
        $_ret = $_client->addNumbers(3, 5);
        echo('<pre>');
        var_dump($_ret);
        echo('<pre>');
        die();
    }
    public function zendserverAction()
    {
        if(isset($_GET['wsdl'])) {
            $_autod = new Zend_Soap_AutoDiscover();
            $_autod->setClass('MySoapServerClass');
            $_autod->handle();
        }
        else {
            $_server = new Zend_Soap_Server('http://localhost/php5_testapp/soap/zendserver?wsdl');
            $_server->setClass("MySoapServerClass");
            $_server->handle();
        }
        exit;
    }
}
/**
 * My Soap Server Class
 */
class MySoapServerClass {
    /**
     * This method adds two numbers
     * 
     * @param integer $a
     * @param integer $b
     * @return string
     */
    public function addNumbers($a, $b) {
        return 'Outcome is: ' . ($a + $b);
    }
}

现在您可以添加所需的任何类!但请记住 - 您的类应该有很好的文档记录,因为 WSDL 文件是基于此生成的。

希望对您有所帮助!