当我尝试在Postman上测试Zend Framework 2中的PUT方法时,为什么必须使用x-www-form-urlencoded
选项?
/*
Use multipart/form-data for testing.
*/
public function create($data)
{
$form = new AlbumForm();
$album = new Album();
$form->setInputFilter($album->getInputFilter());
$form->setData($data);
if ($form->isValid()) {
$album->exchangeArray($form->getData());
$id = $this->getAlbumTable()->saveAlbum($album);
}
return new JsonModel(array(
'data' => $album->extract(),
));
}
/*
Use application/x-www-form-urlencoded for testing.
*/
public function update($id, $data)
{
$data['id'] = $id;
$album = $this->getAlbumTable()->getAlbum($id);
$form = new AlbumForm();
$form->bind($album);
$form->setInputFilter($album->getInputFilter());
$form->setData($data);
if ($form->isValid()) {
$id = $this->getAlbumTable()->saveAlbum($form->getData());
}
return new JsonModel(array(
'data' => $album->extract(),
));
}
如果我选择form-data
选项
Array
(
[------WebKitFormBoundaryP9erwzQtIaB0m0tr
Content-Disposition:_form-data;_name] => "title"
bla bla bla bla xxx
------WebKitFormBoundaryP9erwzQtIaB0m0tr
Content-Disposition: form-data; name="artist"
xxx xxx
------WebKitFormBoundaryP9erwzQtIaB0m0tr--
)
我不明白为什么Zend2会这么做。有任何想法吗?使用x-www-form-urlencoded
优于form-data
- 在Zend2上下文中有什么优势呢?
我可以在Zend2中的某处配置为PUT方法使用form-data
选项吗?