Php 找不到symfony\bundle\frameworkbundle\controller

Php 找不到symfony\bundle\frameworkbundle\controller,php,symfony,silex,Php,Symfony,Silex,似乎无法创建表单,因为找不到frameworkbundle。我真的不知道如何解决这个问题 我尝试使用不同的方法来创建表单,我使用下面的链接来实现这一点 实际上不知道它是否可以解决您的问题,但您的代码中有一个错误: $registration = new UserType(); $form = $this->createForm(new UserType(), $registration, array( 'action' => $this->generateUrl('ac

似乎无法创建表单,因为找不到frameworkbundle。我真的不知道如何解决这个问题

我尝试使用不同的方法来创建表单,我使用下面的链接来实现这一点


实际上不知道它是否可以解决您的问题,但您的代码中有一个错误:

$registration = new UserType();
$form = $this->createForm(new UserType(), $registration, array(
    'action' => $this->generateUrl('account_create'),
));
您应该将新的
User
对象作为第二个参数传递给
$this->createForm
方法,而不是表单对象。参见方法文档

您应该创建用户对象,然后将其传递给
createForm()


更新你的供应商,可能是Brokeri我不知道我需要在composer.json中安装哪个库,你能帮我吗?尝试更新但未工作是否
php composer.phar update
(windows中的
composer update
)运行时未出错?是的,它最终正确更新,但现在我遇到以下问题严格标准:控制器声明\RegisterController:get()应该与symfony\bundle\Frameworkbundle\Controller\Controller的方法兼容父类中已经有一个方法
get
,比如
symfony\bundle\Frameworkbundle\Controller\Controller
重命名您的
get
方法,它应该以world
Action
结束,比如
registerAction
 <?php
 namespace Controllers;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;
 use Forms\UserType;

 class RegisterController extends Controller
 {
public function get(Request $request)
{
    $registration = new UserType();
    $form = $this->createForm(new UserType(), $registration, array(
        'action' => $this->generateUrl('account_create'),
    ));
    if($form->isValid())
    {
        $data = $form->getData();
        echo $data;

        return $app->redirect('login');
    }

    return $app['twig']->render('register.twig', array('form' => $form->createView()));
}
}
$registration = new UserType();
$form = $this->createForm(new UserType(), $registration, array(
    'action' => $this->generateUrl('account_create'),
));
$user = new User();
$form = $this->createForm(new UserType(), $user, array(
    'action' => $this->generateUrl('account_create'),
));