我试图在sfGuard插件中向用户表单中添加一个自定义字段。
我已经在数据库中创建了列,并为该字段添加了widgetschema。它在表单中正确显示,当添加和提交文本时,它将显示更新是成功的。不过,插入到字段中的数据并没有在数据库中填充。
我认为我必须更新sfGuard的模型,因为它不知道这个新的领域。我尝试过$ ./symfony doctrine:build-model,但这似乎没有更新sfGuard插件中的类。
我在sfGuardUserAdminClass中添加了以下内容:
$this->widgetSchema['department_title'] = new sfWidgetFormInputText();
$this->validatorSchema['department_title'] = new sfValidatorString(array());我可以看到表单字段并提交,它只是没有捕获数据并将数据插入到db中。
更新
我用MyUser对象更新了我的模式,迁移了diff并构建了模型。我在$this->embedRelation('Profile');中添加了sfGuardUserAdminForm.class。我收到了这个错误
"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"发布于 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:
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');https://stackoverflow.com/questions/11024158
复制相似问题