On Tue, Nov 4, 2008 at 6:26 PM, [EMAIL PROTECTED] <
[EMAIL PROTECTED]> wrote:

>
>
> >   customer_id: 5,
> >   delivery_date: "Nov 08, 2008",
> >
> > }
> >
> > It would be good if I could do $request->getParameter('order') and
> retrieve
> > an array of values that would be exactly the same as an array of values
> for
> > an 'Order' model as submitted by the standard auto-generated form.  This
> > would enable significant re-use of code for validation of input data.
>
> How would it handle json which is just an array? ["foo","bar']
>

Good question.  The simplest answer is probably to say that not all json
inputs will be processed in this way - if the result of json_decode() is not
an associative array with keys then it makes no sense to use it as I
suggest.  Secondly, the getContent() method that Kris proposes would be a
fall-back mechanism for retrieving 'unusual' json data - there's nothing to
stop you doing json_decode($request->getContent()) on your key-less array.
My suggestion was that Symfony could do the json conversion automatically
and if the result is an array with keys, these are accessible as if they had
been named POST values.

The sole reason for this is that it would make auto-generated CRUD code work
with json inputs, providing a simple API for anyone wanting to pass data to
a Symfony app using json.

Example:
    $this->form->bind($request->getParameter('order'));
    if ($this->form->isValid())
    {
      $order = $this->form->save();

This comes from an auto-generated Update action.  The form contains elements
with names like 'order[customer_id]', 'order[purchase_ref]' and so on.
Therefore $request->getParameter('order') returns an associative array with
members with the keys 'customer_id', 'purchase_ref' etc.  Obviously this is
very similar to a json object with members called 'customer_id',
'purchase_ref' etc. so it makes sense to process them using the same code,
which would require only a small bit of processing by Symfony but would
avoid the need for custom json processing in controller actions.

Not all actions will want this processing, so perhaps it could be
configurable?

-- 
Rob Knight

http://robknight.org.uk

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to