Quantcast

grab value from request, or from form

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

grab value from request, or from form

Steve Rayner-2
In ZF2 i'm trying to hydrate a doctine object from a zend form. The
object's properties are populated ok apart from properties that are other
objects (ie relationships).
Unless there is a better way, i can just create the other objects on the
fly and set the properties of the inital object that i'm trying to hydrate.
(i seem to remember there is a better way of doing this in doctrine)

Now i'm stuck, I can't find in the documentation how i can access a single
parameter from the request object, or from the form object.
Can anyone show me how to do this?

Steve
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: grab value from request, or from form

weierophinney
Administrator
-- Steve Rayner <[hidden email]> wrote
(on Thursday, 26 July 2012, 11:27 PM +0100):

> In ZF2 i'm trying to hydrate a doctine object from a zend form. The
> object's properties are populated ok apart from properties that are other
> objects (ie relationships).
> Unless there is a better way, i can just create the other objects on the
> fly and set the properties of the inital object that i'm trying to hydrate.
> (i seem to remember there is a better way of doing this in doctrine)
>
> Now i'm stuck, I can't find in the documentation how i can access a single
> parameter from the request object, or from the form object.
> Can anyone show me how to do this?

From the form object, what you will do after validation is one of the
following:

    // This is new as of RC1
    $value = $form->get('element-name')->getValue()

    // This will work in beta4 -> current
    $filter = $form->getInputFilter();
    $value  = $filter->getValue('element-name');

To grab from the request, you can use the params() plugin, and pull from
the appropriate source:

    $value = $this->params()->fromPost('key-name');
    $value = $this->params()->fromQuery('key-name');
    $value = $this->params()->fromRoute('key-name');

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Loading...