symfony-4.2 - 覆盖 FOUserBundle 后如何编辑 services.yaml
问题描述
我在 Symfony 4 中将 FOSUserBundle 集成到我的项目中,一切正常。
我的目标:在 user.php 中添加 2 个属性(姓名和名字)。我的步骤:
- 我在 User.php (src Entity User.php) 中添加了这两个属性——好的
- 我搬到我的终端来生成迁移——好的
- 我在 RegistrationFormTYpe.php 中创建了新文件夹 Form(src Form)和新文件(见背景)
- 我编辑了 services.yaml(见背景)
我在 (config fos_user.yaml) 中编辑了 fos_user.yaml..可能是错误的文件..因为 symfony 3 中不存在 config.yaml(参见背景)
在后台看到控制台错误...有人有解决方案吗?我必须放弃在 symfony 4 中集成 fosuser 吗?
//src\窗体;
namespace src\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseRegistrationFormType;
class RegistrationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name',TextType::class,array(
'label' => 'Nom',
'required' => TRUE,
'attr' =>array(
'class='=>'form-group form-control'
)
))
->add('firstname',TextType::class,array(
'label' => 'Prénom',
'required' => TRUE,
'attr' =>array(
'class='=>'form-group form-control'
)
))
;
}
public function getParent(){
return BaseRegistrationFormType::class;
}
public function getBlockPrefix()
{
return 'app_user_registration';
}
}
// 配置\services.yaml
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: 'fr'
services:
app.form.registration:
class: AppBundle\Form\RegistrationFormType
tags:
- { name: form.type }
- { firstname: form.type }
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,EventListener,Migrations,Tests,Kernel.php}'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
// 配置\fos_user.yaml
fos_user:
db_driver: orm
user_class: App\Entity\User
firewall_name: main
service:
mailer: fos_user.mailer.noop
from_email:
address: "sebvrg@gmail.com"
sender_name: "sebvrg@gmail.com"
registration:
form:
type: AppBundle\Form\RegistrationFormType
// 在控制台输出:
In FileLoader.php line 166:
A "tags" entry is missing a "name" key for service "app.form.registration" in C:\Users\sebvr\Desktop\Projets\SELT\selt\config/services.yaml in C:\Users\sebvr\Deskt
op\Projets\SELT\selt\config/services.yaml (which is loaded in resource "C:\Users\sebvr\Desktop\Projets\SELT\selt\config/services.yaml").
In YamlFileLoader.php line 489:
A "tags" entry is missing a "name" key for service "app.form.registration" in C:\Users\sebvr\Desktop\Projets\SELT\selt\config/services.yaml.
解决方案
您是否也扩展了您的用户实体?
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
/**
* @ORM\Entity
* @ORM\Table(name="`user`")
*/
class User extends BaseUser
{
/**
* @ORM\Column(type="string")
*/
private $name;
/**
* @ORM\Column(type="string")
*/
private $firstname;
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
public function getFirstname()
{
return $this->firstname;
}
public function setFirstname($firstname)
{
$this->firstname = $firstname;
}
}
您是否在 app/config/config.yml 中注册了表单?
fos_user:
registration:
form:
type: AppBundle\Form\RegistrationFormType
您的标签也显示 Symfony 4.2,但您使用的是 symfony 3 (AppBundle) 而不是 (App) 的结构
推荐阅读
- android - 抽屉预览未在菜单文件中正确显示
- html - Bootstrap 列中的垂直对齐项目
- vba - 如果变量 AND 变量 Then
- javascript - 如何根据字段搜索嵌套对象和分组
- macos - 如果我在套接字过滤器中设置了一个 mbuf 标记,我以后可以在 IP 过滤器中找到这些标记的数据包吗?
- bash - 脚本在 crontab debian 和 ubuntu 上不起作用
- visual-studio - 扩展不下载/更新
- discord - 如何向机器人所在的 2 台服务器发送消息,节点不和谐
- docusignapi - 将 DocuSign 页面批量链接到客户
- laravel - Laravel登录而不签入数据库