tags:

views:

2425

answers:

3

I'm using Symfony 1.2 in a standard Propel form class.

public function configure()
{
    $this->setWidgets(array( 
'graduate_job_title' => new sfWidgetFormInput( array(), array( 'maxlength' => 80, 'size' => 30, 'value' => '' ) )
    ));
    //etc
}

However, I want the value of this field to come from the user information, which I'd normally access using $this->getUser()->getAttribute( '...' ). However, this doesn't seem to work in the form.

What should I be using?

+3  A: 
lpfavreau
Works, thank you!
James Inman
Thank you, it works
Nordes
+3  A: 

It's a very bad idea to rely on the sfContext instance. It's better to pass what you need during sfForm initialization in the options array parameter.

http://www.symfony-project.org/api/1_4/sfForm

__contruct method

for example in your action:

$form = new myForm(null, 
                   array('attributeFoo' => 
                         $this->getUser()->getAttribute('attributeFoo'));

and then retrieve the value inside the form class:

$this->getOption('attributeFoo');

cirpo

cirpo
A: 

@cirpo why do you considered it is a bad idea to use sfContext ?