-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possibility to use arrays in fields #63
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 Originally posted by @Michal-sk at zfcampus/zf-apigility#70 (comment) |
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. Originally posted by @Wilt at zfcampus/zf-apigility#70 (comment) |
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:
Originally posted by @Michal-sk at zfcampus/zf-apigility#70 (comment) |
@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. Originally posted by @Michal-sk at zfcampus/zf-apigility#70 (comment) |
I am not sure what you want to achieve. From the Originally posted by @Wilt at zfcampus/zf-apigility#70 (comment) |
Array values as defined in foobar example. And get them from the raw data param which we have in the controllers Originally posted by @Michal-sk at zfcampus/zf-apigility#70 (comment) |
Maybe the problem lies in your
Originally posted by @Wilt at zfcampus/zf-apigility#70 (comment) |
No, i use multiform Originally posted by @Michal-sk at zfcampus/zf-apigility#70 (comment) |
Created a pull request for this, maybe that makes it more obviouse; pull request: zfcampus/zf-content-negotiation#57 Originally posted by @Michal-sk at zfcampus/zf-apigility#70 (comment) |
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
Originally posted by @jg-development at zfcampus/zf-apigility#70
The text was updated successfully, but these errors were encountered: