I tried this this solution, but it seams not to work in Symfony 1.4. Has something changed? How do I add selected attribute to the form select?
Here is my form class:
// /lib/form/doctrine/CurrencyListForm.class.php
class CurrencyListForm extends BaseCurrencyForm
{
public function configure()
{
$choices = '';
$choice = Doctrine::getTable('currency')
->createQuery('a')
->execute();
foreach($choice as $v)
开发者_开发知识库 $choices[$v->getCurrencyCode()] = $v->getCurrencyCode();
$this->setWidgets(array(
'currency_code' => new sfWidgetFormSelect(array('choices' => $choices)),
));
}
}
And this is how I instantiate it:
$this->form = new CurrencyListForm();
What kind of form are you rendering? If it's an object form (like sfFormDoctrine
), the binding 'reverts' the defaults. (It sets the defaults of the model).
What I found was the simplest way to bind it, is creating a dummy object and set the property on that object. Then pass this object to the constructor of the form.
Something like this:
$defaultCurrency = new Currency();
$defaultCurrency->currency_code = 'EUR';
$this->form = new CurrencyListForm($defaultCurrency);
精彩评论