0

我正在使用 symfony 中的 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;
}

这是我的肥皂客户

$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;
4

2 回答 2

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 ...以防万一。

于 2012-04-02T17:43:53.270 回答
0

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

$arrRequests != arrRequests

ckSoapParameterFilter已经将@param $arrRequests转换为没有$的简单参数,因此您不需要它。

它应该是:

public function executeUpdateRequests(sfWebRequest $request)
{
   $res = $request->getParameter('arrRequests');
   $this->result = $res;
   return sfView::SUCCESS;
}
于 2014-04-22T22:23:50.930 回答