csDoctrineActAsAttachablePlugin - 1.0.0

Attach custom and preset filetypes to your modules

You are currently browsing
the website for symfony 1

Visit the Symfony2 website

« Back to the Plugins Home


Forgot your password?
Create an account



advanced search
Information Readme Releases Changelog Contribute
Show source



This behavior permits to attach files to Doctrine objects.


  • add/remove attached files on an object / multiple object classes
  • validate uploaded files
  • validate according to file type
  • supports the module csAttachable that allows for ajax includes to upload and add files to a given class

Supported filetypes are the following:

  • image
  • audio
  • video
  • document
  • application
  • custom
  • other

The type "other" represents the base filetype, and is not validated by mimetype.
Others can be set accordingly.


add the following code to your module's schema file:

    actAs: [Attachable]

csAttachable module

To use csAttachable module, add csAttachable to your settings.yml under "enabled_modules" and add the following code to your template:

<?php include_component('csAttachable', 'attachments', array('form' => $form)) ?>

where $this->form represents the Doctrine Form for whatever class is acting as attachable. It is important to note the plugin does not work if the passed $this->form does not carry an object already saved to the database. For this reason, the component should not be included unless the form object exists, for example:

<?php if ($form->getObject()->getId()): ?>
    <?php include_component('csAttachable', 'attachments', array('form' => $form)) ?>
<?php endif; ?>

Also supported is the csAttachable attachments_list component, which receives an object variable and outputs a UL of attachments and their links. This is handy for frontend development / archive reasons, and also serves as an example for how attachments should be accessed / displayed. Use the following code to access this component:

<?php include_component('csAttachable', 'attachments_list', array('object' => $object)) ?>

Where $object is an item acting as Attachable

Other available methods include

  • $model->getAttachments(); Returns a doctrine collection object of related attachemnts
  • $model->addAttachment($attachment) where $attachment is an Attachment object
  • $model->addAttachments($attachments) where $attachments is an array or collection of Attachment objects.
  • $attachment->getObject(); where $attachment is the attachment object returning its related model

Other Notes

Using the included partial, Attachment objects are hashed and placed in uploads/(model)/(file) where (model) is the model acting as Attachable. The Attachment object is then assigned the previous filename to it's [name] property.

Array accessors are not yet available for ActAsAttachable. For example, $model['Attachments'] will return an error.

To Do

  • Add automated mimetype validation for specified types
  • Allow relationships specified in schema.yml to validate for specific types
  • Allow multiple attachable types in schema.yml (for example, UserProfile has Video and Image attachments for Video and Photo galleries)
  • Have automatic mimetype/extension parsing to determine attachment's type