2011-07-13 42 views
0

我正在用symfony中的ckWebServicePlugin制作webservice。 我设法使用一个简单的参数类型和一个复杂的类型作为回报的方法,它运作良好,但是当我试图在参数中获取一个复杂类型的数组时,它似乎返回一个空值;ckWebServicePlugin中的复杂类型参数数组是空的

/api/actions.class.php

/** Allow to update request 
* 
* @WSMethod(name='updateRequests', webservice='api') 
* 
* @param RequestShort[] $arrRequests 
* 
* @return RequestShort[] $result 
*/ 
public function executeUpdateRequests(sfWebRequest $request) 
{ 
    $res = $request->getParameter('$arrRequests'); 
    $this->result = $res; 
    return sfView::SUCCESS; 
} 

,这是我的SOAP客户端

$test = array(array('request_id' => 1, 'statut' => 3), array('request_id' => 2, 'statut' => 3),); 
$result = $proxy->updateRequests($test); 

,这是我RequestShort型

class RequestShort { 
/** 
* @var int 
*/ 
public $request_id; 
/** 
* @var int 
*/ 
public $statut; 

public function __construct($request_id, $statut) 
{ 
    $this->request_id = $request_id; 
    $this->statut = $statut; 
} 
} 

最后,我的app.yml

soap: 
    # enable the `ckSoapParameterFilter` 
    enable_soap_parameter: on 
    ck_web_service_plugin: 
    # the location of your wsdl file 
    wsdl: %SF_WEB_DIR%/api.wsdl 
    # the class that will be registered as handler for webservice requests 
    handler: ApiHandler 
    soap_options: 
     classmap: 
     # mapping of wsdl types to PHP types 
     RequestShort: RequestShort 
     RequestShortArray: ckGenericArray 

下面的代码如何返回什么?

$res = $request->getParameter('$arrRequests'); 
$this->result = $res; 

回答

1

在我看来,在:

$res = $request->getParameter('$arrRequests'); 
$this->result = $res; 
return sfView::SUCCESS; 

拼错参数getParameter()功能。

也许这应该是这样的:

$res = $request->getParameterHolder()->getAll(); 
$this->result = $res; 
return sfView::SUCCESS; 

而且不要忘记做symfony cc && symfony webservice:generate-wsdl ...以防万一。

0

这是因为你得到了错误的参数。

$arrRequests != arrRequests 

ckSoapParameterFilter已经翻译@param $ arrRequests到没有$简单的参数,所以你并不需要它。

它应该是:

public function executeUpdateRequests(sfWebRequest $request) 
{ 
    $res = $request->getParameter('arrRequests'); 
    $this->result = $res; 
    return sfView::SUCCESS; 
}