Development

IrcFAQ

You must first sign up to be able to contribute.

Version 1 (modified by raphaelburnes, 7 years ago)
--

A collection of questions I see often in irc.freenode.com #symfony.

Most seem to relate to symfony 1.4 and Doctrine.

Q: How do I get the name of a related model object to show up instead of the id in a dropdown?

A: create a toString method in lib/model/doctrine/ModelName.class.php ( or lib/model/ModelName.class.php for Propel )

public function __toString()
{
  return $this->getName();
}

Q: What is the difference between ModelName?.class.php and ModelNameTable?.class.php (Doctrine)

A: ModelName?.class.php is for operating on a single instance or record of that type, whereas ModelNameTable?.class.php is for operating on the entire related table. For example:

// $onePerson is an instance of the Person class, retrieved with the PersonTable class
$onePerson = PersonTable::getInstance()->findOneByName('Bob');

// Get a Doctrine Collection of some people records with the PersonTable class.
$people = PersonTable::getInstance()->findAll();

foreach($people as $person)
{
  // each $person is an instance of the plain Person class.
  $person->getName();
}


Q: How can I use multiple databases in symfony?

A: Doctrine: http://symfony-world.blogspot.com/2010/05/multiple-database-symfony-configuration.html[[BR]] A: Propel: http://stackoverflow.com/questions/733224/multiple-databases-support-in-symfony


Q: How can I set a default form parameter in my form?

A: Create a new object for the form, set the parameter you want on it, and pass it to the form.

  $person = new Person();
  $person->setName($request->getParameter('paramName'));
  $this->form = new PersonForm($person);