Symfony 1.4Propel (with sfPropel15Plugin)
我有一个多语言库与以下模式:
# Galleries
pi_gallery:
_attributes:
phpName: Gallery
isI18N: true
i18nTable: pi_gallery_i18n
_propel_behaviors:
sortable: ~
id: ~
active:
type: boolean
default: true
required: true
created_at: ~
updated_at: ~
pi_gallery_i18n:
_attributes:
phpName: GalleryI18n
id:
type: integer
foreignTable: pi_gallery
foreignReference: id
required: true
primaryKey: true
onDelete: cascade
culture:
isCulture: true
type: varchar
size: 7
required: true
primaryKey: true
name:
type: varchar
size: 255
required: false
description:
type: longvarchar
required: false
# Images
pi_gallery_image:
_attributes:
phpName: GalleryImage
isI18N: true
i18nTable: pi_gallery_image_i18n
id: ~
gallery_id:
type: integer
foreignTable: pi_gallery
foreignReference: id
required: true
image:
type: varchar
size: 255
required: true
created_at: ~
updated_at: ~
pi_gallery_image_i18n:
_attributes:
phpName: GalleryImageI18n
id:
type: integer
foreignTable: pi_gallery_image
foreignReference: id
required: true
primaryKey: true
onDelete: cascade
culture:
isCulture: true
type: varchar
size: 7
required: true
primaryKey: true
description:
type: varchar
size: 255
required: false
我正在尝试使用以下方式在图库中嵌入图像表单:
# GalleryForm.class
public function configure()
{
unset(
$this['alias'],
$this['created_at'],
$this['updated_at']
);
$this->widgetSchema['article_id']->setOption('renderer_class', 'sfWidgetFormPropelJQueryAutocompleter');
$this->widgetSchema['article_id']->setOption('renderer_options', array(
'model' => 'Article',
'url' => '/article/ajax'
));
$this->validatorSchema['article_id'] = new sfValidatorPass();
$this->embedI18n(array('es', 'en', 'de', 'it', 'fr'));
$this->widgetSchema->setLabel('en','English');
$this->widgetSchema->setLabel('es','Español');
$this->widgetSchema->setLabel('de','Deutsch');
$this->widgetSchema->setLabel('it','Italiano');
$this->widgetSchema->setLabel('fr','Francais');
$this->embedRelation('GalleryImage'); // Embeds the Relation between the GalleryImage model and the Gallery Model
}
# GalleryImageForm.class:
public function configure()
{
unset(
$this['created_at'],
$this['updated_at'],
$this['gallery_id'],
$this['sortable_rank']
);
if ($this->isNew()) unset($this['id']);
$this->embedI18n(array('es', 'en', 'de', 'it', 'fr'));
$image = $this->getObject()->getImage();
$template = (!is_null($image) || $image != "") ? '<div>%file%<br />%input%<br />%delete% %delete_label%</div>' : '';
$this->widgetSchema['image'] = new sfWidgetFormInputFileEditable(array(
'label' => 'Imagen',
'file_src' => '/'.sfConfig::get('sf_upload_dir_name').'/images/galleries/thumbs/'.substr($this->getObject()->getImage(),0,-4) . '.jpg',
'is_image' => true,
'edit_mode' => !$this->isNew() && $image != "",
'with_delete' => true,
'delete_label'=>'Eliminar archivo existente',
'template' => $template
));
$this->validatorSchema['image_delete'] = new sfValidatorPass();
$this->validatorSchema['image'] = new sfValidatorFile(array(
'path' => sfConfig::get('sf_upload_dir').'/images/galleries',
'required' => false,
'mime_types' => 'web_images'
));
}
这似乎像预期的那样嵌入表单…最初。GalleryForm出现时带有多语言描述和嵌入在它们下面的ImageForms。到目前为止一切顺利。
然而,保存表单显示一切都不太好。
最初保存两条记录,一条仅保存图像,另一条仅保存i18n字段。i18n字段还添加了第二个记录的id,因此无法将图像与i18n字段关联起来。也许保存表格的顺序不对?
有没有人成功地得到了一个形式的工作,嵌入I18n嵌入关系?或者有人有什么解决办法吗?我读过一些关于重写saveEmbeddedForms的东西,但我甚至不知道从哪里开始。
感谢您的帮助。
修复了sfPropelORMPlugin:
- https://github.com/propelorm/sfPropelORMPlugin/issues/13
- https://github.com/propelorm/sfPropelORMPlugin/pull/76
- https://github.com/propelorm/sfPropelORMPlugin/issues/38