可能的重复:
Symfony 生成器形式、学说和 M:N 关系
我有一个基本的 M:N 设置,包含三个表:候选、位置和候选位置。这是我对鱼尾纹风格 ERD 的最佳尝试,只有文字
[candiate]-||------|<[candidate_position]>|------||-[position]
我想要完成的是:当candidate
创建或编辑 a 时,表单将包含一个复选框数组,其中包含所有可用职位的分配给候选人。
在 Web 应用程序开发的正常世界中,这真的非常非常容易。但是我正在尝试使用 symfony 的管理生成器来提高我的能力。这是我到目前为止所得到的
应用程序/后端/模块/condidate/config/generator.yml
generator:
class: sfDoctrineGenerator
param:
model_class: Candidate
theme: admin
non_verbose_templates: true
with_show: false
singular: ~
plural: ~
route_prefix: candidate
with_doctrine_route: true
actions_base_class: sfActions
config:
actions: ~
fields:
first_name: { label: First Name }
last_name: { label: Last Name }
created_at: { label: Created On }
positions: {}
list:
sort: [last_name, asc]
filter: ~
form:
display:
"User": [first_name, last_name]
"Applying For": [positions]
fields :
hide: [created_at]
edit: ~
new: ~
lib/form/doctrine/candidateForm.class.php
class candidateForm extends BasecandidateForm
{
public function configure()
{
unset( $this['created_at'] );
$this->widgetSchema['positions'] = new sfWidgetFormDoctrineChoice(
array( 'multiple' => true, 'model' => 'Position', 'renderer_class' => 'sfWidgetFormSelectCheckbox' )
);
$this->validatorSchema['positions'] = new sfValidatorDoctrineChoice(
array( 'multiple' => true, 'model' => 'Position', 'min' => 1 )
);
}
}
配置/教义/schema.yml
candidate:
columns:
id:
type: integer(4)
primary: true
unsigned: true
notnull: true
autoincrement: true
first_name:
type: string(45)
notnull: true
last_name:
type: string(45)
notnull: true
created_at:
type: integer(4)
unsigned: true
position:
columns:
id:
type: integer(4)
primary: true
unsigned: true
notnull: true
autoincrement: true
name:
type: string(45)
candidatePosition:
tableName: candidate_position
columns:
candidate_id:
type: integer(4)
primary: true
unsigned: true
notnull: true
position_id:
type: integer(4)
primary: true
unsigned: true
notnull: true
relations:
candidate:
class: candidate
local: candidate_id
foreign: id
foreignAlias: candidate_positions
position:
class: position
local: position_id
foreign: id
foreignAlias: candidate_positions
indexes:
fk_candidate_position_candidate1:
fields: [candidate_id]
fk_candidate_position_position1:
fields: [position_id]
这行得通!排序 =/
复选框呈现到创建和编辑屏幕,但数据不保存。显然(?)我需要对模型进行一些定制(lib/model/doctrine/candidate.class.php),这就是我失去焦点的地方。我不确定如何从内部获取候选人[职位]数据candidate::save()
- PHP 5.2.x
- symfony 1.4.3