Symfony在Form类中获取提交的值

我需要在模型后面生成的表格中使用sfValidatorDoctrineChoice的提交值。</ p>
\ n

我尝试了 $ this-&gt; getValue('country')</ code>但它无效:</ p>

  $ query2 = Doctrine_Core :: getTable  ('sate') - &gt; createQuery('s')

  • &gt; select('s.id')
  • &gt; where('s.idcountry =?',$ this-&gt; getValue(' country'));
    </ code> </ pre>

    如何获取该参数?</ p>
    </ div>

展开原文

原文

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?

php

3个回答



  $ somevar = sfContext :: getInstance() - &gt; getRequest() - &gt; getParameter('register')\  n $ query2 = Doctrine_Core :: getTable('sate') - &gt; createQuery('s')

  • &gt; select('s.id')
  • &gt; where('s.idcountry =?', $ somevar ['country']);
    </ code> </ pre>

    这个有效。</ p>
    </ div>

展开原文

原文

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

This one works.



如果您正在进入*表格,请尝试:</ p>

  $ query2 = Doctrine_Core  :: getTable('sate') - &gt; createQuery('s')

  • &gt; select('s.id')
  • &gt; where('s.idcountry =?',$ this-&gt; getObject() - &gt; getCountry());
    </ code> </ pre>

    否则,如果您进入动作类,则需要使用 $ this-&gt; form- &gt; getObject() - &gt; getCountry()</ code>。</ p>
    </ div>

展开原文

原文

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

dqvy87517
dqvy87517 SELECT COUNT(*)AS num_results FROM sate WHERE idcountry =''AND id ='2'它仍然没有为idcountry返回该值
大约 9 年之前 回复



请记住,sfContext不是免费的:)</ p>

测试一堆依赖的代码 上下文非常难,因为你需要引导一个完整的symfony上下文,从而失去了测试的隔离。</ p>

另外,请记住你正在访问表单中的整个Request对象, 难闻的气味。</ p>

请尝试遵循Fabio Cinerchia的提示。</ p>
</ div>

展开原文

原文

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.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐