我正在使用Doctrine和FOSBundle 2.0在Symfony3中开发应用程序。
我一直在尝试在我的注册栏中添加两个字段 firstName 和 lastName 。
I have found this tutorial on how do do precisely what I'm hoping,不幸的是在最初的几个步骤之后(处理之前)我发现我收到了这个错误:
无法加载类型" app_user_registration"
我使用的代码是从网站上精心复制,唯一的区别是我的课程看起来像这样
<?php
// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/** @ORM\Column(type="integer") */
protected $carma;
/**
* @ORM\Column(type="string", length=255)
*
* @Assert\NotBlank(message="Please enter your first name.", groups={"Registration", "Profile"})
* @Assert\Length(
* min=3,
* max=255,
* minMessage="The name is too short.",
* maxMessage="The name is too long.",
* groups={"Registration", "Profile"}
* )
*/
protected $firstName;
/**
* @ORM\Column(type="string", length=255)
*
* @Assert\NotBlank(message="Please enter your first name.", groups={"Registration", "Profile"})
* @Assert\Length(
* min=3,
* max=255,
* minMessage="The name is too short.",
* maxMessage="The name is too long.",
* groups={"Registration", "Profile"}
* )
*/
protected $lastName;
当存在名为...&#34; name&#34;
的变量时会发生相同的效果我花了最后几个小时试图找出答案。 有我试过的:
其他所有内容都将我的输出代码显示为问题的回答。
任何人都可以帮助一个可怜的灵魂吗?
另外,这是我的其他文件:
//config.yml
/*...*/
fos_user:
db_driver: orm
firewall_name: main
user_class: AppBundle\Entity\User
registration:
form:
type: AppBundle\Form\RegistrationType
//services.yml
services:
app.form.registration:
class: AppBundle\Form\RegistrationType
tags:
- { name: form.type, alias: app_user_registration }
//RegistraionType.php
<?php
// src/AppBundle/Form/RegistrationType.php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class RegistrationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('firstName');
}
public function getParent()
{
return 'fos_user_registration';
}
public function getName()
{
return $this->getBlockPrefix();
}
public function getBlockPrefix()
{
return 'app_user_registration';
}
}
答案 0 :(得分:3)
你应该使用这个tuorial(2.0.master): http://symfony.com/doc/master/bundles/FOSUserBundle/overriding_forms.html
您正在使用教程“1.3.x版本”。
对于Symfony3,您必须进行此更改:
class RegistrationType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('name'); } public function getParent() { return 'FOS\UserBundle\Form\Type\RegistrationFormType'; } public function getBlockPrefix() { return 'app_user_registration'; } }
services: app.form.registration: class: AppBundle\Form\RegistrationType tags: - { name: form.type, alias: app_user_registration }
fos_user: # ... registration: form: type: AppBundle\Form\RegistrationType
答案 1 :(得分:0)
我怀疑您一直在尝试按照教程扩展注册表单。您最有可能在app / config / services.yml文件中包含以下条目:
char buffer[20] = {0};
//populate the buffer
const char *finalized = buffer;
然后在你的src / AppBundle / Form / RegistrationType.php中你应该有以下功能:
app.form.registration:
class: AppBundle\Form\RegistrationType
tags:
- { name: form.type, alias: app_user_registration }
这很可能是在getBlockPrefix()方法中出现错误的地方。检查您的services.yml并与我发布的内容进行比较。我从我自己的应用程序中抓取了它,工作正常。