Symfony sfWidgetFormDoctrineChoice 与“多个” =>真的
我使用 symfony 1.4.11 和原则。架构的一部分:
Companies:
actAs:
Timestampable: ~
Sluggable:
unique: true
fields: [company]
canUpdate: false
builder: [myTools, StripText]
connection: doctrine
tableName: companies
columns:
company_id: { type: integer(4), primary: true, notnull: true, autoincrement: true }
user_id: { type: int(4) }
category_id: { type: int(4), notnull: true }
company: { type: string(255), notnull: true }
address: { type: string(255), notnull: true }
contact_person: { type: string(255), notnull: true }
phone: { type: string(50), notnull: true }
fax: { type: string(50) }
email: { type: string(255), notnull: true}
url: { type: string(50) }
about: { type: string(1000), notnull: true}
country: { type: string(255), notnull: true}
show_ads: { type: boolean, default: 0 }
active: { type: boolean, default: 0 }
has_company: { type: boolean, default: 1 }
relations:
Owner: { onDelete: CASCADE, local: user_id, foreign: id, class: sfGuardUser, foreignAlias: Companies }
Images_companies: { local: company_id, foreign: company_id, type: many, class: Images_companies }
Categories: { onDelete: CASCADE, local: category_id, foreign: category_id , type: many, foreignType: one}
Categories:
actAs:
I18n:
fields: [name]
actAs:
Sluggable:
unique: true
fields: [name]
canUpdate: true
builder: [myTools, StripText]
NestedSet:
hasManyRoots: true
connection: doctrine
tableName: categories
columns:
category_id: { type: integer(4), primary: true, autoincrement: true }
name: string(255)
我希望用户可以为公司选择多个类别。我使用 sfWidgetFormDoctrineChoice ,所以当我让
$this->widgetSchema['category_id'] = new sfWidgetFormDoctrineChoice(array('model' => 'Categories', 'add_empty' => false, 'multiple' => false));
用户只能选择一个类别时,一切都可以。 当我有:
$this->widgetSchema['category_id'] = new sfWidgetFormDoctrineChoice(array('model' => 'Categories', 'add_empty' => false, 'multiple' => true));
并从列表中仅选择一个类别,在数据库中保存category_id = 0。当我选择多个类别时,出现错误: SQLSTATE[HY093]: 无效的参数号:绑定变量的数量与标记的数量不匹配
我在谷歌中搜索此错误,但我没有找到决定,而且我现在不知道我在哪里做出的有事吗。谢谢你!
I use symfony 1.4.11 with doctrine. So part of schema :
Companies:
actAs:
Timestampable: ~
Sluggable:
unique: true
fields: [company]
canUpdate: false
builder: [myTools, StripText]
connection: doctrine
tableName: companies
columns:
company_id: { type: integer(4), primary: true, notnull: true, autoincrement: true }
user_id: { type: int(4) }
category_id: { type: int(4), notnull: true }
company: { type: string(255), notnull: true }
address: { type: string(255), notnull: true }
contact_person: { type: string(255), notnull: true }
phone: { type: string(50), notnull: true }
fax: { type: string(50) }
email: { type: string(255), notnull: true}
url: { type: string(50) }
about: { type: string(1000), notnull: true}
country: { type: string(255), notnull: true}
show_ads: { type: boolean, default: 0 }
active: { type: boolean, default: 0 }
has_company: { type: boolean, default: 1 }
relations:
Owner: { onDelete: CASCADE, local: user_id, foreign: id, class: sfGuardUser, foreignAlias: Companies }
Images_companies: { local: company_id, foreign: company_id, type: many, class: Images_companies }
Categories: { onDelete: CASCADE, local: category_id, foreign: category_id , type: many, foreignType: one}
Categories:
actAs:
I18n:
fields: [name]
actAs:
Sluggable:
unique: true
fields: [name]
canUpdate: true
builder: [myTools, StripText]
NestedSet:
hasManyRoots: true
connection: doctrine
tableName: categories
columns:
category_id: { type: integer(4), primary: true, autoincrement: true }
name: string(255)
I want that user can choose for company , more than one category. I use sfWidgetFormDoctrineChoice ,so when I have
$this->widgetSchema['category_id'] = new sfWidgetFormDoctrineChoice(array('model' => 'Categories', 'add_empty' => false, 'multiple' => false));
User can choose only one category , it is all ok.
When I have:
$this->widgetSchema['category_id'] = new sfWidgetFormDoctrineChoice(array('model' => 'Categories', 'add_empty' => false, 'multiple' => true));
And choose only one category from list , in db save category_id = 0 . When I choose more than one category, I have error :
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
I search this error in google, but I don't find the decision, and I do not now where I make something wrong. Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就我而言,我必须修改验证器:
In my case, I had to modify the validator:
您定义关系的方式不允许您为您的公司选择多个类别。您可能想改为建立多对多关系。
http://www.doctrine-project.org/projects/orm/1.2/docs/manual/defining-models/en#relationships:join-table-associations:many-to-many
The way you defined your relation does not allow you to choose more than one category for you company. You may want to set up many-to-many relation instead.
http://www.doctrine-project.org/projects/orm/1.2/docs/manual/defining-models/en#relationships:join-table-associations:many-to-many