Symfony:如何反转“notnull:true”在插件的架构中?
sfDoctrineGuardPlugin 的 sfGuardUser 模型是这样定义的:
sfGuardUser:
actAs: [Timestampable]
columns:
id:
type: integer(4)
primary: true
autoincrement: true
username:
type: string(128)
notnull: true
unique: true
如您所见,'username' 具有“notnull:true”功能。现在我想要 创建一个不使用“用户名”而是使用电子邮件的注册表单 用户的地址。
当用户想要注册时,会显示以下内容:
sfGuardUser 类验证失败 1 个字段存在验证错误: * 1 个验证器在用户名上失败(notnull)
知道吗?
哈维
sfGuardUser model of sfDoctrineGuardPlugin is defined this way:
sfGuardUser:
actAs: [Timestampable]
columns:
id:
type: integer(4)
primary: true
autoincrement: true
username:
type: string(128)
notnull: true
unique: true
As you can see 'username' has the feature "notnull:true". Now i want
to create a register form that is not using 'username' but the email
address of the user.
When a user wants to register, it is showed this:
Validation failed in class sfGuardUser
1 field had validation error:
* 1 validator failed on username (notnull)
Any idea?
Javi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我最终用另一个显示“notnull:false”的模式覆盖该模式。从 sf1.3 开始这是可能的。
I finally overwrite the schema with another schema that says "notnull:false". This is possible from sf1.3.
在 symfony 1.4 中,最终类生成到主 lib 目录中,以便您可以在项目中修改它们。
因此,在 lib/model/doctrine/sfDoctrineGuardPlugin/sfGuardUser.class.php 文件中,您可以覆盖负责模型定义的 setUp() 方法:
In symfony 1.4 final classes are generated to main lib directory so you could modify them in project.
Therefore in lib/model/doctrine/sfDoctrineGuardPlugin/sfGuardUser.class.php file you are able to overwrite setUp() method which is responsible for model definition:
一些插件模式字段可以轻松调整,无需调整代码,而另一些则会抛出错误。
您可以尝试从架构中的用户名字段中删除“notnull: true”,但它可能会引发错误(尚未尝试)。在这种情况下,您可以调整插件代码(=头痛),或者确保始终将值保存到该字段,例如零。这样它就永远不会为空。
Some of the plugin schema fields are easily adjustable without code tweaks, while others will throw an error.
You could try removing "notnull: true" from the username field in the schema, but it may throw an error (haven't tried). In this case, you can either tweak the plugin code (=headache), or ensure that a value is always saved to that field, such as a zero. This way it's never null.
您可以通过以下方式修复
lib/form/doctrine/sfGuardPlugin/sfGuardUserForm.class.php
:you could fix
lib/form/doctrine/sfGuardPlugin/sfGuardUserForm.class.php
in following way: