0

我正在尝试呈现我刚刚从实体生成的表单,但我收到以下错误...

<?php

namespace Prueba\FrontendBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Prueba\FrontendBundle\Form\ItemType;

class DefaultController extends Controller
{
/**
* @Route("/hello")
* @Template()          
*/                      
public function indexAction($name)       
{                              
     $form = new ItemType();var_dump(get_class($form));                                 
                return $this->render('AcmeTaskBundle:Default:new.html.twig', array(             
                                        'form' => $form->createView(),
                                                 ));
    }                            
}

string(35) "Prueba\FrontendBundle\Form\ItemType" 致命错误:调用 /home/javier/programacion/sf2000/src/Prueba/FrontendBundle/Controller/ 中未定义的方法 Prueba\FrontendBundle\Form\ItemType::createView()第 20 行的 DefaultController.php

4

1 回答 1

1

改变

$form = new ItemType();

$form = $this->createForm(new FormType());

如果您想将一个空实体附加到表单(更容易验证和表单处理):

$item = new Item();
$form = $this->createForm(new FormType(), $item);
于 2012-05-07T17:15:50.830 回答