-
Notifications
You must be signed in to change notification settings - Fork 51
Possibility to use arrays in fields #70
Comments
I made a quick patch which works with the multiform and can handle flat arrays. Deep arrays Index: vendor/zfcampus/zf-content-negotiation/src/MultipartContentParser.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>windows-1252
===================================================================
--- vendor/zfcampus/zf-content-negotiation/src/MultipartContentParser.php (revision d779bbfde1cc5802c0d6a5f2ac9cc34bf5b71475)
+++ vendor/zfcampus/zf-content-negotiation/src/MultipartContentParser.php (revision )
@@ -111,7 +111,9 @@
// Time to handle the data we've already parsed!
// Data
if (! $filename) {
- $data->set($name, rtrim($content, "\r\n"));
+// $content = rtrim($content, "\r\n");
+// $data->set($name, $content);
+ $this->processContent($data, $name, $content);
}
// File (successful upload so far)
@@ -264,6 +266,35 @@
}
return $data->toArray();
+ }
+
+ /**
+ * Process the non-file data.
+ * @param Parameters $parameters
+ * @param $name
+ * @param $content
+ */
+ protected function processContent(Parameters $parameters, $name, $content)
+ {
+ $isArray = strstr($name, '[]');
+ $name = rtrim($name, '[]');
+ $content = rtrim($content, "\r\n");
+
+ if ($parameters->offsetExists($name)) {
+ $data = $parameters->get($name);
+
+ if (is_array($data)) {
+ $data[] = $content;
+ } else {
+ $data = [$data, $content];
+ }
+
+ $parameters->set($name, $data);
+ } elseif ($isArray) {
+ $parameters->set($name, (array) $content);
+ } else {
+ $parameters->set($name, $content);
+ }
}
/** It will behave somewhat like the |
I am not exactly sure where you do not manage to configure your nested field. But Apigility is definitely able to handle such cases. Check an example here on stackoverflow. |
When i was implementing your SO solution i had the feeling that it's for a fixed list? What if i would want to accept a normal array. So my post could contain:
|
@Wilt i found some other posts of you regarding this aswell as the post about the raw $data param we have in the methods. I am using this raw $data param, and that doesnt seem to work with arrays. |
I am not sure what you want to achieve. From the |
Array values as defined in foobar example. And get them from the raw data param which we have in the controllers |
Maybe the problem lies in your
|
No, i use multiform |
Created a pull request for this, maybe that makes it more obviouse; pull request: zfcampus/zf-content-negotiation#57 |
This repository has been closed and moved to laminas-api-tools/api-tools; a new issue has been opened at laminas-api-tools/api-tools#63. |
Hi,
I want to post 2 addresses in one request.
(like billingaddress and deliveryaddress)
It seems Apigility cannot work with a fieldname like "billingAddress[salutation]". In the config this is just a string and not an array. Is it in any way possible to use input parameters as arrays?
Greetings Jan
The text was updated successfully, but these errors were encountered: