This is probably an easy question but since I’m new with Symfony it’s still a bit confusing.
I have a Podcast table which has a user_id column that is related to my sfGuardUser table which has an id column. (A user creates a podcast and his ID is saved automatically in the Podcast table, creator_id column)
Then, I have a PodcastForm where by default doctrine created this widget in the BasePodcastForm.class.php:
'creator_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('sfGuardUser'), 'add_empty' => false)),
Which creates a dropdown in the podcast form.
In my PodcastForm.php, I have:
public function configure() {
$this->widgetSchema['creator_id'] = new sfWidgetFormInputText(array(),array('readonly' => 'true'));
...
}
But the problem is that it shows me the ID of the user instead of the name. In the sfGuardUser.class.php file I created the __toString() method returning the user’s Username, but it stills shows the Id instead.
How could I do to show the Users’ Username instead of the Id in the Podcast form as a sfWidgetFormInputText?
I hope to understand well what you need… you could add as a new widget the username with a code like this:
Maybe some adaptation is necessary because I use
Propel.Finally, it’s a bad practice to use the singleton
sfContext::getInstance()->...inside a form, but this is another matter.[update] As Flukey said in his comment, just passing the user object through as a form option allows to remove the need for the sfContext singleton completely.