Fredlab,
  First I don't think that it was necessary to overwrite the
executeUpdate.  processForm was protected and not private and this is
where you wanted to overwrite, just to add tot he bind function.
{{{
#!php
#/apps/admin/modules/images/actions/actions.class.php
class imagesActions extends autoImagesActions
{

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter('image'), $request->getFiles
('image'));
    if ($form->isValid())
    {
      $this->getUser()->setFlash('notice', $form->getObject()->isNew
() ? 'The item was created successfully.' : 'The item was updated
successfully.');

      $image = $form->save();

      $this->dispatcher->notify(new sfEvent($this,
'admin.save_object', array('object' => $image)));

      if ($request->hasParameter('_save_and_add'))
      {
        $this->getUser()->setFlash('notice', $this->getUser()->getFlash
('notice').' You can add another one below.');

        $this->redirect('@images_new');
      }
      else
      {
        $this->redirect('@images_edit?id='.$image['id']);
      }
    }
    else
    {
      $this->getUser()->setFlash('error', 'The item has not been saved
due to some errors.');
    }
  }
}
}}}

However, all of that is not necessary after today since Jonathon.Wage
has fixed that ticket.

However, to make the file upload work you should upload your form
class.  In my case it looks like this:
{{{
#!
/lib/form/doctrine/ImageForm.class.php
<?php

/**
 * Image form.
 *
 * @package    form
 * @subpackage Image
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27
06:22:40Z fabien $
 */
class ImageForm extends BaseImageForm
{
  /**
  * Here I'm updating the fields to be an InputFileEditable and
telling it where the file is stored and that it's an image
  */
  public function configure()
  {
    unset($this['updated_at'], $this['created_at'], $this['slug']);
    $this->widgetSchema['filename'] = new sfWidgetFormInputFileEditable
(array('file_src' => '/uploads/'.$this->getObject()->getFilename(),
'is_image' => true));
    $this->validatorSchema['filename'] = new sfValidatorFile();

  }

  /**
  * Here I'm making deleting the old file on save if it exists, making
the filename, and setting the filename in the database on save
  */
  public function doSave($con = null)
  {
    if (file_exists($this->getObject()->getFilename()))
    {
      unlink($this->getObject()->getFilename());
    }

    $file = $this->getValue('filename');
    $filename = sha1($file->getOriginalName()).$file->getExtension
($file->getOriginalExtension());
    $file->save(sfConfig::get('sf_upload_dir').'/'.$filename);

    return parent::doSave($con);
  }


  /**
  * Here I'm changing the full absolute file path to just the relative
path on update
  */
  public function updateObject($values = null)
  {
    $object = parent::updateObject($values);

    $object->setFilename(str_replace(sfConfig::get
('sf_upload_dir').'/', '', $object->getFilename()));

    return $object;
  }

}
}}}

Like I said all of this can be found and explained at
http://www.symfony-project.org/book/forms/1_2/en/11-Doctrine-Integration

Hope this helps you and anyone else that needs this functionality.

P.s. Like I wrote originally the delete uploaded file checkbox
functionality does not work for this widget.

-- Stephen Ostrow <[EMAIL PROTECTED]>

On Nov 17, 12:55 pm, fredlab <[EMAIL PROTECTED]> wrote:
> Stephen: I did overwrite my executeUpdate function as it is public
> while the processform is private (did it under the action.class.php of
> the author module).
>
> This is my code :
>
> lass authorsActions extends autoAuthorsActions
> {
>   public function executeUpdate(sfWebRequest $request)
>   {
>     $this->author = $this->getRoute()->getObject();
>     $this->form = $this->configuration->getForm($this->author);
>
>     $this->form->bind($request->getParameter('author'), 
> $request->getFiles('author'));
>
>     if ($this->form->isValid())
>     {
>       $this->getUser()->setFlash('notice', $this->form->getObject()->isNew() 
> ? 'The item was created successfully.' : 'The item was
>
> updated successfully.');
>
>         $module_name = $this->getContext()->getModuleName();
>         $file = $this->form->getValue('file');
>         $filename =  $module_name;
>         $extension = $file->getExtension($file->getOriginalExtension
> ());
>         $file->save(sfConfig::get('sf_app_module_dir').'/'.
> $module_name.'/'.sfConfig::get('sf_upload_dir').'/'.$filename.
> $extension);
>         $this->getUser()->setFlash('error', sfConfig::get
> ('sf_app_module_dir').'/'.$module_name.'/'.sfConfig::get
> ('sf_upload_dir').'/'.$filename.$extension.' ___FILENAME :'.$file);
>
>    // ...
>       $author = $this->form->save();
>
>       $this->dispatcher->notify(new sfEvent($this,
> 'admin.save_object', array('object' => $author)));
>
>       if ($request->hasParameter('_save_and_add'))
>       {
>         $this->getUser()->setFlash('notice', $this->getUser()->getFlash
> ('notice').' You can add another one below.');
>
>         $this->redirect('@authors_new');
>       }
>       else
>       {
>         $this->redirect('@authors_edit?id='.$author['id']);
>       }
>     }
>     else
>     {
>       $this->getUser()->setFlash('error', 'The item has not been saved
> due to some errors.');
>     }
>     $this->setTemplate('edit');
>   }
>
> }
>
> Hope it can helps someone.
>
> Note that I also added under my AuthorForm.class.php file in the
> configure section :
>
>  $this->widgetSchema['file'] = new sfWidgetFormInputFile(array
> ('needs_multipart' => true));
>  $this->validatorSchema['file'] = new sfValidatorFile();
>
> Regards.
>
> Frédéric
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to