Quick Tip for File Uploader in Symfony 1.2

symfonySo in symfony < ver 1.2, in the backend you could update the generator.yml to change a field type to make it more like a file upload button. I would usually substitute type: admin_input_file_tag and that would automagically convert it to a file upload.

Starting 1.2.x you cant do that anymore. It has quite logically so changed, so instead of changing it in the generator.yml you make the change in the forms class instead. So in my example I have a class called Album Class and I have a field called Album Cover, so i updated the AlbumForm.class.php and store this in there.

class AlbumForm extends BaseAlbumForm
{
  public function configure()
  {
    $this->setWidget('album_cover', new sfWidgetFormInputFile());
    $this->setValidator('album_cover', new sfValidatorFile(array('path' => 'uploads/')));
  }
}

That updates it inthe admin tool and more so, even on the frontend, there is more like a consistent use experience. Like I always say Symfony is awesome.

About rp

Architect for large, highly scalable LAMP applications and Technical Manager with special focus on metrics based continuous improvement of teams and products. Rajat has close to a decade of experience of a very wide range of skills related to infrastructure, middleware, app servers all the way to front-end technologies and software development methodologies including agile, iterative waterfall, waterfall as well as ah-hoc startup using the right approach in the right context to reduce time to market.