Daniel
Daniel

Reputation: 418

Symfony get submitted values in Form class

I need to use a submitted value for sfValidatorDoctrineChoice in a form generated after a model.

I tried $this->getValue('country') but it's not working:

$query2 = Doctrine_Core::getTable('sate')->createQuery('s')
            ->select('s.id')
            ->where('s.idcountry = ?', $this->getValue('country'));

How can I get that parameter?

Upvotes: 2

Views: 795

Answers (3)

odino
odino

Reputation: 1069

Remember, sfContext is not for free :)

Testing a bunch of code which relies on the context is really hard, as you need to bootstrap an entire symfony context, thus loosing test's isolation.

Additionally, bear in mind that you are accessing the entire Request object in a Form, a bad smell.

Try, instead, to follow Fabio Cinerchia's hints.

Upvotes: 0

Daniel
Daniel

Reputation: 418

$somevar = sfContext::getInstance()->getRequest()->getParameter('register')
$query2 = Doctrine_Core::getTable('sate')->createQuery('s')
        ->select('s.id')
        ->where('s.idcountry = ?', $somevar['country']);

This one works.

Upvotes: 0

Fabio Cicerchia
Fabio Cicerchia

Reputation: 679

If you are into a *Form try this:

$query2 = Doctrine_Core::getTable('sate')->createQuery('s')
            ->select('s.id')
            ->where('s.idcountry = ?', $this->getObject()->getCountry());

Otherwise if you are into an action class you need to use $this->form->getObject()->getCountry().

Upvotes: 4

Related Questions