我正在使用Doctrine和FOSBundle 2.0開發Symfony3中的應用程序。嘗試將字段添加到註冊表單時,無法加載類型「app_user_registration」
我一直在試圖兩個字段添加到我的註冊欄的firstName和lastName的。
I have found this tutorial on how do do precisely what I'm hoping,不幸的是,前幾個步驟(前處理)我知道我得到這個錯誤後:
Could not load type "app_user_registration"
我使用的是exacly複製從網站的代碼,唯一的區別是我的課看起來像這樣
<?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;
相同效應發生時,有一個叫......「名」
變量我花了最後幾個小時試圖弄清楚。 有什麼我曾嘗試:
- 使用2.0高手版教程
- The answer form here
其他一切表明我的輸出代碼爲答案的問題。
任何人都可以幫助一個可憐的靈魂嗎?
作爲補充,這裏是我的其他文件:
//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';
}
}
此錯誤是不是在你的用戶的實體,它試圖使用你已經設置別名在您的應用程序來/ config/services.yml參考您的用戶註冊表單。 – pogeybait
你是否也做過表單類型的東西,因爲這是錯誤來自哪裏。當你尋找其他例子時要小心。您發佈的第二個鏈接是針對舊版本的FOSUserBundle。事實上,你會發現大多數例子都過時了。 – Cerad