2

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?

3 Answers 3

4

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().

Sign up to request clarification or add additional context in comments.

1 Comment

SELECT COUNT(*) AS num_results FROM sate WHERE idcountry = '' AND id = '2' It still doesn't return that value for idcountry
0
$somevar = sfContext::getInstance()->getRequest()->getParameter('register')
$query2 = Doctrine_Core::getTable('sate')->createQuery('s')
        ->select('s.id')
        ->where('s.idcountry = ?', $somevar['country']);

This one works.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.