Ciężko zrozumieć o co Ci dokładnie chodzi :). Ogólny schemat wygląda tak:
Tworzysz sobie model:
<?php
class Month
{
private $input1;
private $input2;
public function getInput1()
{
return $this->input1;
}
public function setInput1($input1)
{
$this->input1 = $input1;
}
public function getInput2()
{
return $this->input2;
}
public function setInput2($input2)
{
$this->input2 = $input2;
}
}
Najprostszym podejściem jest utworzenie forma w kontrolerze, połączenie go z modelem i przekazanie do widoku:
class MonthController extends Controller
{
public function monthAction(Request $request)
{
$month = new Month();
$monthForm = $this->createFormBuilder($month)
->add('input1', 'text')
->add('input2', 'text')
->add('submit', 'submit', array('label' => 'Submit month'))
->getForm();
return $this->render('template:name.html.twig', array(
'monthForm' => $monthForm->createView(),
));
}
}
Potem renderowanie formularza w widoku(najprostsze podejście):
{{ form(monthForm) }}
Jeżeli chciałbyś połączyć to z bazą danych. To już zależy od tego czego używasz. Z Doctrinem wygląda to tak:
class MonthController extends Controller
{
public function addMonthAction(Request $request)
{
$month = new Month();
$monthForm = $this->createFormBuilder($month)
->add('input1', 'text')
->add('input2', 'text')
->add('submit', 'submit', array('label' => 'Submit month'))
->getForm();
$monthForm->handleRequest($request);
if ($monthForm->isValid()) {
$manager = $this->getDoctrine()->getManager();
$manager->persist($month);
$manager->flush();
}
return $this->render('template:name.html.twig', array(
'monthForm' => $monthForm->createView(),
));
}
}