También lo he intentando en este controller donde solo hay un formulario, a ver si se puede ver mas claro
Código PHP:
use SymfonyBundleFrameworkBundleControllerController;
use TMKSeriesBundleEntitySeries;
use TMKSeriesBundleFormRegisterSerieType;
class DefaultController extends Controller
{
public function indexAction($name)
{
return $this->render('TMKSeriesBundle:Default:index.html.twig', array('name' => $name));
}
public function loadSeriesAction($state)
{
$request = $this->getRequest();
$form = $this->createFormAddSerie($request);
if($state == '0'){
$title = 'Siguiendo';
$state = array(0,3);
} else if($state == '1'){
$title= 'Vistas';
} else if ($state == '2'){
$title = 'Pendientes';
}
$manager = $this->getDoctrine()->getManager();
$series = $manager->getRepository('TMKSeriesBundle:Series')->findByStateOrderBy($state);
return $this->render('TMKSeriesBundle:Default:series.html.twig', array(
'series' => $series,
'title' => $title,
'form' => $form->createView()
));
}
public function createFormAddSerie($request){
$serieForm = new Series();
$form = $this->createForm(new RegisterSerieType, $serieForm);
if($request->getMethod() == 'POST'){
$form->bind($request);
if($form->isValid()){
$manager = $this->getDoctrine()->getManager();
$manager->persist($serieForm);
$manager->flush();
return $this->redirect($this->generateURL('loadSeries', array('state' => $serieForm->getState())));
}
}
return $form;
}
}