一部のデータはフォームから送信するユーザーからのもので、残りの部分は実際のコントローラーで生成されます。だから、のようなもの:私はそれを検証し、それを持続できるようにSymfony2のコントローラー内で送信されたフォームオブジェクトにデータを追加します。
# controller
use Acme\SomeBundle\Entity\Variant;
use Acme\SomeBundle\Form\Type\VariantType;
public function saveAction()
{
$request = $this->getRequest();
// adding the data from user submitted from
$form = $this->createForm(new VariantType());
$form->bindRequest($request);
// how do I add this data to the form object for validation etc
$foo = "Some value from the controller";
$bar = array(1,2,3,4);
/* $form-> ...something... -> setFoo($foo); ?? */
if ($form->isValid()) {
$data = $form->getData();
// my service layer that does the writing to the DB
$myService = $this->get('acme_some.service.variant');
$result = $myService->persist($data);
}
}
にはどうすれば$form
オブジェクトに$foo
と$bar
を得るのですか?ここで