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?
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()
.
$somevar = sfContext::getInstance()->getRequest()->getParameter('register')
$query2 = Doctrine_Core::getTable('sate')->createQuery('s')
->select('s.id')
->where('s.idcountry = ?', $somevar['country']);
This one works.
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.
精彩评论