首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >向sfGuard用户管理表单中添加新的用户字段

向sfGuard用户管理表单中添加新的用户字段
EN

Stack Overflow用户
提问于 2012-06-13 22:20:41
回答 1查看 1.6K关注 0票数 1

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

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

我认为我必须更新sfGuard的模型,因为它不知道这个新的领域。我尝试过$ ./symfony doctrine:build-model,但这似乎没有更新sfGuard插件中的类。

我在sfGuardUserAdminClass中添加了以下内容:

代码语言:javascript
复制
$this->widgetSchema['department_title'] = new sfWidgetFormInputText();
$this->validatorSchema['department_title'] = new sfValidatorString(array());

我可以看到表单字段并提交,它只是没有捕获数据并将数据插入到db中。

更新

我用MyUser对象更新了我的模式,迁移了diff并构建了模型。我在$this->embedRelation('Profile');中添加了sfGuardUserAdminForm.class。我收到了这个错误

代码语言:javascript
复制
"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"
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-14 09:11:17

如果您真的想向用户模型中添加一个字段,就必须修改plugins/sfDoctrineGuardPlugin/config/doctrine/schema.yml中的plugins/sfDoctrineGuardPlugin/config/doctrine/schema.yml配置。找到表sfGuardUser并添加您的列。但这不是一个好的方法,如果你更新插件,你会失去你的改变。

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

代码语言:javascript
复制
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

在重新生成所有这些属性之后,可以通过以下方式访问自定义属性:

代码语言:javascript
复制
$context->getUser()->getProfile()->getDepartementTitle();

并且可以将生成的MyUserProfileForm表单嵌入到sfGuardUserAdminForm表单中:

代码语言:javascript
复制
$this->embedRelation('Profile');
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11024158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档