Ver Mensaje Individual
  #10 (permalink)  
Antiguo 03/11/2015, 01:34
Chino27
 
Fecha de Ingreso: septiembre-2015
Mensajes: 71
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: Formularios en distinto método

Muy bien, noto como si lo tuviera casi, pero también quiero meter la ejecución del formulario, para eso he tenido que crear un objeto controller, esta es mi clase

Código PHP:
<?php

namespace TMKSeriesBundleUtils
;

use 
SymfonyBundleFrameworkBundleControllerController;
use 
SymfonyComponentFormFormFactoryInterface;
use 
TMKSeriesBundleEntitySeries;
use 
TMKSeriesBundleFormRegisterSerieType;

class 
FormCreator
{
    public 
$formFactoryInterface;
    
    public function 
__construct(FormFactoryInterface $formFactoryInterface){
        
$this->formFactoryInterface $formFactoryInterface;
    }
    
    public function 
getFormAddSerie($request){
        
$controller = new Controller();
        
$serie = new Series();
        
$form $this->formFactoryInterface->create(new RegisterSerieType(), $serie);
        
        if(
$request->getMethod() == 'POST'){
            
$form->bind($request);
            
            if(
$form->isValid()){
            
$manager $controller->getDoctrine()->getManager();
                
$manager->persist($serie);
                
$manager->flush();

                return 
$this->redirect($this->generateURL('loadSeries', array('state' => $serie->getState())));
            }
        }
        
        return 
$form;
    }

}
?>
Pero me devuelve este error:
FatalErrorException: Error: Call to a member function has() on null in /Applications/MAMP/htdocs/seriesmoko/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php line 198

Es cuando intenta hacer esta linea
Código PHP:
$manager $controller->getDoctrine()->getManager(); 
Este es el método del archivo controller:
Código PHP:
public function getDoctrine()
    {
        if (!
$this->container->has('doctrine')) {
            throw new 
LogicException('The DoctrineBundle is not registered in your application.');
        }

        return 
$this->container->get('doctrine');
    } 
PD: Estoy aprendiendo paso a paso symfony, pero me cuesta mucho mucho. Gracias

Última edición por Chino27; 03/11/2015 a las 01:52 Razón: Añadido el método del archivo controller