2009年10月12日星期一

Re: [fw-mvc] Get request in my form

Hm.

Now it works with 

$request = Zend_Controller_Front::getInstance()->getRequest();
$param = $request->getParam($param);

thanks Ruslan!

I can swear that is the first and most logical think I tried and didn't work... :)

Regards,
Saša Stamenković


On Mon, Oct 12, 2009 at 10:01 AM, Nick Pack <nick@nickpack.com> wrote:
umpirsky wrote:
Hi.

I have class which extends Zend_Form. What I want to do during elements
initialization is to assign default values to elements from the request. But
I cant reach getParam method from the form. Is there some elegant way to do
this (without passing all values to form constructor)?

In your controller where you initiate your form you can call the populate() method, e.g.

public function IndexAction()
{
$request = $this->getRequest();
$form = new MyForm();

// $request->getParam('name');
// Sanitise params and assign them to array $values[]

$form->populate($values);

没有评论: