Symfony1 将新用户字段添加到sfGuard用户管理表单

Symfony1 将新用户字段添加到sfGuard用户管理表单,symfony1,symfony-1.4,symfony-forms,sfguard,Symfony1,Symfony 1.4,Symfony Forms,Sfguard,我正在尝试向sfGuard插件中的用户表单添加一个自定义字段 我已经在数据库中创建了该列,并为该字段添加了widgetschema。它在表单中正确显示,当添加和提交文本时,它显示更新成功。但是,插入到字段中的数据不会填充到数据库中 我想我必须更新sfGuard的模型,因为它不知道这个新领域。我尝试过$./symfony原则:构建模型,但这似乎并没有更新sfGuard插件中的类 我已将此添加到sfGuardUserAdminClass: $this->widgetSchema['depart

我正在尝试向sfGuard插件中的用户表单添加一个自定义字段

我已经在数据库中创建了该列,并为该字段添加了widgetschema。它在表单中正确显示,当添加和提交文本时,它显示更新成功。但是,插入到字段中的数据不会填充到数据库中

我想我必须更新sfGuard的模型,因为它不知道这个新领域。我尝试过
$./symfony原则:构建模型
,但这似乎并没有更新sfGuard插件中的类

我已将此添加到sfGuardUserAdminClass:

$this->widgetSchema['department_title'] = new sfWidgetFormInputText();
$this->validatorSchema['department_title'] = new sfValidatorString(array());
我可以看到表单字段并提交,它只是没有捕获数据并将其插入数据库

更新

我已经用MyUser对象更新了我的模式,迁移了diff并构建了模型。我添加了
$this->embedderelation('Profile')。我得到了这个错误

"Catchable fatal error: Argument 1 passed to sfUser::__construct() must be an instance of sfEventDispatcher, instance of MyUserTable given, called in /Users/careyestes/Sites/sva/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Table.php on line 301 and defined in /Users/careyestes/Sites/sva/lib/vendor/symfony/lib/user/sfUser.class.php on line 46 Fatal error: Call to a member function evictAll() on a non-object in /Users/careyestes/Sites/sva/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 1239"

如果你真的想在用户模型中添加一个字段,你必须在
plugins/sfDoctrineGuardPlugin/config/doctor/schema.yml
中修改schema.yml配置。找到表sfGuardUser并添加您的列。但这不是一个好办法,因为如果你更新插件,你将丢失你的更改

最好是创建一个专用表,该表将以一对一的关系链接到sfGuardUser模型。在config/doctor/schema.yml中创建表MyUserProfile:

MyUserProfile:
  columns:
    id: { type: integer, primary: true, autoincrement: true }
    sf_guard_user_id: { type:integer }
    department_title: { type: string(255) }
    # ... other column definitions
  relations:
    User:
     class: sfGuardUser
     foreignType: one
     foreignAlias: Profile
     local: sf_guard_user_id
     onDelete: CASCADE
重建全部后,可通过以下方式访问自定义属性:

$context->getUser()->getProfile()->getDepartementTitle();
您可以将生成的MyUserProfileForm表单嵌入到sfGuardUserAdminForm表单中:

$this->embedRelation('Profile');

如果你真的想在用户模型中添加一个字段,你必须在
plugins/sfDoctrineGuardPlugin/config/doctor/schema.yml
中修改schema.yml配置。找到表sfGuardUser并添加您的列。但这不是一个好办法,因为如果你更新插件,你将丢失你的更改

最好是创建一个专用表,该表将以一对一的关系链接到sfGuardUser模型。在config/doctor/schema.yml中创建表MyUserProfile:

MyUserProfile:
  columns:
    id: { type: integer, primary: true, autoincrement: true }
    sf_guard_user_id: { type:integer }
    department_title: { type: string(255) }
    # ... other column definitions
  relations:
    User:
     class: sfGuardUser
     foreignType: one
     foreignAlias: Profile
     local: sf_guard_user_id
     onDelete: CASCADE
重建全部后,可通过以下方式访问自定义属性:

$context->getUser()->getProfile()->getDepartementTitle();
您可以将生成的MyUserProfileForm表单嵌入到sfGuardUserAdminForm表单中:

$this->embedRelation('Profile');

我通过更新sfguard模式使其正常工作。我不知道如果我升级,我会丢失那些模式设置。我将把它用于开发。谢谢。我通过更新sfguard模式使其正常工作。我不知道如果我升级,我会丢失那些模式设置。我将把它用于开发。谢谢。很抱歉,可能名称MyUser是错误的,因为它也是sfUser的默认类的名称。尝试将架构中的名称从MyUser更改为MyUserProfile。我更新了我的答案。很抱歉,可能名称MyUser是错误的,因为它也是sfUser的默认类的名称。尝试将架构中的名称从MyUser更改为MyUserProfile。我更新我的答案。