在php中添加zend框架的自定义类型?

时间:2012-04-17 07:30:46

标签: php zend-framework

我无法使用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,但它对我没有帮助。

1 个答案:

答案 0 :(得分:1)

在您发表评论后,我决定重写我的答案并为您提供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文件是基于此生成的。

希望它有所帮助!