Hi everyone. I want to create a module for Categories. Every category
has 1 or more images. The i18n fields are: title and description.
Basically, I have in CategoriesForm.class.php (I won't put the exact
script, but the essencial things just to show you my point. It would
be too long if I put the complete script):

<?php
    class CategoryForm extends BaseCategoryForm
    {
         public function configure()
         {
               $this->embedI18n( array( 'en', 'es' ) );

               $imagesCollectionForm = new ImagesCollectionForm( $this-
>getObject() );

               $this->embedForm( 'imagesCollection',
$imagesCollectionForm );

               $this->embedRelation( 'Images' );
         }

         public function saveEmbeddedForms( $con = null, $forms =
null )
         {
              if ( $forms === null )
              {
                   $images  = $this->getValue( 'imagesCollection' );
                   $forms    = $this->embeddedForms;

                   foreach ( $forms[ 'imagesCollection' ] as $name =>
$form )
                   {
                        if ( !isset( $images[ $name ] ) )
                        {
                             unset( $forms[ 'imagesCollection' ]
[ $name ] );
                        }
                   }
              }

              return parent::saveEmbeddedForms( $con, $forms );
         }
    }
?>


Ok, suppose that the model "Category" are related to the model
"Image". Then I create a "ImagesCollectionForm" that, basically, embed
to itself two "ImageForm" (just like it's explained in the book "More
with Symfony": 
http://www.symfony-project.org/more-with-symfony/1_4/en/06-Advanced-Forms

In this way the form appears correctly. I did everything just like the
book says (except for the i18n part that I had to add myself).

>From here, my questions:

1) Is this the better way to do it for i18n forms?

2) I'm having trouble with thumbnail generation and deleting the
images when I update or delete them. How would I, for example, create
two thumbnails from each added or modified Image? I thought on putting
the generation code on the "Image" model, overriding the "save"
function. Could it be like this?


public function save( Doctrine_Connection $con = null )
{
      // .. more functions.. generateThumbnails()... deleteImages()..
etc

      // if getLink() returns '' it means that an image needs to be
added
      if ( $this->getLink() !== '' )
      {
            if ( !$this->isNew() )
            {
                   $this->deleteImages();
            }

            $this->generateThumbnails();
      }

      parent::save( $con );
}



$this->getLink() in this case represents the value that it's submitted
with the form or the "link" field that's actually in the DB (if the
object is being modified)?

If my questions are a little tricky, please, could you tell me the
steps to create a form with i18n behavior and adding to it an
imagesCollection form in the correct way? which functions would I need
to override and in which classes? I red every book of Symfony but
there's some little things that I still don't know exactly how they
work. If you could give me some steps to do it and a brief explanation
of why it has to be in that way.. it would be incredibly useful for
me.


Thanks in advance.

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

To unsubscribe, reply using "remove me" as the subject.

Reply via email to