Symfony 1.4 Propel (с плагином sfPropel15)
У меня есть многоязычная галерея со следующей схемой:
# 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 с многоязычными описаниями и встроенными формами изображений под ними. Все идет нормально.
Однако сохранение формы показывает, что не все в порядке.
Изначально сохраняются две записи, одна только с изображением, а другая только с полями i18n. В поля i18n также добавлен идентификатор второй записи, поэтому нет возможности связать изображение с полями i18n. Может порядок сохранения форм неверный?
Кто-нибудь успешно получил форму для работы, которая встраивает I18n во встроенное отношение? Или у кого-нибудь есть идеи обходного пути? Я читал что-то о переопределении saveEmbeddedForms, но я даже не знаю, с чего начать.
Любая помощь приветствуется.