Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
An easy way to add multiple uploads to your model
PHP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
config
lib
modules/upload
README.markdown

README.markdown

sfUploadPlugin

Add multiple uploads to your models using this plugin's widgets and validators

Installation

With git

git submodule add git://github.com/bshaffer/sfUploadPlugin.git plugins/sfUploadPlugin
git submodule init
git submodule update

With subversion

svn propedit svn:externals plugins

In the editor that's displayed, add the following entry and then save

sfUploadPlugin https://svn.github.com/bshaffer/sfUploadPlugin.git

Finally, update:

svn up

Setup

In your config/ProjectConfiguration.class.php file, make sure you have the plugin enabled.

$this->enablePlugins('sfUploadPlugin');

Publish your assets

./symfony plugin:publish-assets

Clear your cache

./symfony cc

Usage

This plugin is very simple, and provides two very useful classes for attaching multiple files to an object

  • sfWidgetFormInputFileMultiple
  • sfValidatorFileMultiple

In order to use these classes, you must have a field of type array on your model. This should be done in config/doctrine/schema.yml. Note: this field type is only available with doctrine objects. Read more on array field types here

MyModelForm:
  columns:
    uploads:
      type:     array
      default:  null

Set the widget and validator to sfWidgetFormInputFileMultiple and sfValidatorFileMultiple in your model's form class

class MyModelForm extends BaseMyModelForm
{
  public function configure()
  {
    $this->setWidget('uploads', new sfWidgetFormInputFileMultiple());
    $this->setValidator('uploads', new sfValidatorFileMultiple());
  }
}

sfWidgetFormInputFileMultiple

This class extends sfWidgetFormInputFile and has the following additional options:

  • max - the max number of uploads allowed on the object. Set to null if there is no maximum
  • disable_js - enable this to use the plugin without javascript enabled.

sfValidatorFileMultiple

This class extends sfValidatorFile and has the following additional options:

  • max - the max number of uploads allowed on the object. Displays the max error message if it fails
Something went wrong with that request. Please try again.