I have the following problem : I want to be able to have an editable
image in my backend form for an element called Horse. This element has
a field "Image" that contains the name of the image and that image has
to be stored in "uploads/images/pferde/%name_slug%/" where %name_slug%
is a slugified value of the field "Name".

Now below you have my BackendKdHorseForm with the widgetSchema and
validatorSchema for the field "Image". It works perfectly fine as long
as I am editing a Horse, but when I try to creat a new one it uploads
the image into "uploads/images/pferde/" instead of "uploads/images/
pferde/%name_slug%". Now I am guessing that in the creation process
the validatorSchema for "Image is unable to find a value for $this-
>getObject()->getNameSlug() and thats why my image ends up in "uploads/
images/pferde/", my question is how can I modify this validatorSchema
in order for the creation process to upload the image in the right
place.
Just for information I did try to use Kd::slugify($this->getValue
('name')) instead of $this->getObject()->getNameSlug() but it still
didn't work...

class BackendKdHorseForm extends KdHorseForm
{
        public function configure()
        {
                parent::configure();

                $this->widgetSchema['image'] = new sfWidgetFormInputFileEditable
(array(
            'label'     => 'Bild',
            'file_src'  => '/uploads/images/pferde/'.$this->getObject()-
>getNameSlug().'/'.$this->getObject()->getImage(),
            'is_image'  => true,
            'edit_mode' => !$this->isNew(),
            'template'  => '<table class="null"><tr><td colspan="2">%file%</
td></tr><tr><td  colspan="2">%input%</td></tr><tr><td>%delete%</td><td>
%delete_label%</td></tr></table>',
          ));

                $this->validatorSchema['image'] = new sfValidatorFile(array(
      'required'   => false,
      'path'       => sfConfig::get('sf_upload_dir').'/images/pferde/'.
$this->getObject()->getNameSlug(),
      'mime_types' => 'web_images',
                        'validated_file_class' => 'sfValidatedFileOriginalName'
    ));

          $this->validatorSchema['image_delete'] = new sfValidatorPass();
        }
}

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

Reply via email to