Attachment Functionality

Adding attachment functionality into your custom module is fairly easy thanks to the built in features in Zurmo.  Follow the three step process outlined below:

1. Add a field in the module model

In the module model in getDefaultMetadata function, add a relation to the File Model and specify the element to use.

2. Add the “files” field to the view

In the Edit and Detail Views, the field name (“files”) is not specified in the view, only “Files” type. This is because we are taking advantage of derived attribute types, similar to “DateTimeCreatedUser”.

3. Update Default Controller of the module.

Since you can attach multiple files, you need to update the controller to be able to handle multiple files on post. Add the following functions to the Default Controller of the custom module:



Leave a Comment

  • Steve F

    Followed instructions, tried to upload a file, and result was:

    An error has occurred. Please click here to continue to the home page. If the error persists please contact your administrator.

    SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘account_id’ in ‘field list’

    Tried adding the column in the table account of “files, file, and filesIds” with no luck. Any assistance?

    • Ray Stoeckicht

      Not sure what is happening. Come join the Dev Session this Tuesday and we will help you resolve it. We have Developer Sessions every Tuesday at
      10:00AM Chicago Time:

      • Bashar T

        Were you able to resolve this issue? I tried adding an attachment to the Opportunity module but I am also getting a very similar error.

        SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘opportunity_id’ in ‘field list’

      • Wiggert de Haan

        I have the same issue. Any hints on what to do?

      • Wiggert de Haan

        It creates the image record in the mySQL database but i guess it fails to create another record that is responsible for attaching it to the right module field (in my case opportunities)

  • Guest

    Hi. I have added the animal module in the application and I implemented the steps above. The same problem goes as the previous comments, but the animal is created anyway. When you try to view the info of the specific animal, the filename of the attachment is not printed (see picture below)

    Any ideas how I can print the attachment’s filename?

  • nizar

    i have this message… after doing this tutorial…. please.. i need help…

  • Guest

    this error

  • Thinh Nguyen

    Fix: replace the code above with this (in the module Model file):

    => array(static::HAS_MANY, ‘FileModel’, RedBeanModel::OWNED, static::LINK_TYPE_POLYMORPHIC, ‘relatedModel’),

    • Dario

      beautifull, but report don’t work… any idea??? the error is 2015/12/16 15:09:43 [error] [exception.NotSupportedException] exception ‘NotSupportedException’ with message ‘files’ in ….. appprotectedmodulesreportsadaptersModelRelationsAndAttributesToReportAdapter.php:514

  • Dario

    followed instruction and everything work fine, i’ve only problem with report.
    this is the log:
    2015/12/16 16:09:24 [error] [exception.NotSupportedException] exception ‘NotSupportedException’ with message ‘files’ in C:EasyPHP-Webserver-14.1b2wwwcontestsappprotectedmodulesreportsadaptersModelRelationsAndAttributesToReportAdapter.php:514
    Stack trace:
    #0 C:EasyPHP-Webserver-14.1b2wwwcontestsappprotectedmodulesreportsadaptersReportRelationsAndAttributesToTreeAdapter.php(129): ModelRelationsAndAttributesToReportAdapter->getSelectableRelationsDataResolvedForUserAccess(Object(User), Array)
    #1 C:EasyPHP-Webserver-14.1b2wwwcontestsappprotectedmodulesreportsadaptersReportRelationsAndAttributesToTreeAdapter.php(88): ReportRelationsAndAttributesToTreeAdapter->getChildrenNodeData(Object(ModelRelationsAndAttributesToSummationReportAdapter), NULL, NULL, NULL)
    #2 C:EasyPHP-Webserver-14.1b2wwwcontestsappprotectedmodulesreportscontrollersDefaultController.php(233): ReportRelationsAndAttributesToTreeAdapter->getData(‘source’)
    #3 [internal function]: ReportsDefaultController->actionRelationsAndAttributesTree(‘Summation’, ‘Filters’, NULL, ‘source’, false)
    #4 C:EasyPHP-Webserver-14.1b2wwwcontestsyiiframeworkwebactionsCAction.php(108): ReflectionMethod->invokeArgs(Object(ReportsDefaultController), Array)
    #5 C:EasyPHP-Webserver-14.1b2wwwcontestsyiiframeworkwebactionsCInlineAction.php(47): CAction->runWithParamsInternal(Object(ReportsDefaultController), Object(ReflectionMethod), Array)
    #6 C:EasyPHP-Webserver-14.1b2wwwcontestsyiiframeworkwebCController.php(308): CInlineAction->runWithParams(Array)
    #7 C:EasyPHP-Webserver-14.1b2wwwcontestsyiiframeworkwebfiltersCFilterChain.php(133): CController->runAction(Object(CInlineAction))
    #8 C:EasyPHP-Webserver-14.1b2wwwcontestsyiiframeworkwebfiltersCFilter.php(40): CFilterChain->run()
    #9 C:EasyPHP-Webserver-14.1b2wwwcontestsyiiframeworkwebfiltersCFilterChain.php(130): CFilter->filter(Object(CFilterChain))
    #10 C:EasyPHP-Webserver-14.1b2wwwcontestsyiiframeworkwebCController.php(291): CFilterChain->run()
    #11 C:EasyPHP-Webserver-14.1b2wwwcontestsyiiframeworkwebCController.php(265): CController->runActionWithFilters(Object(CInlineAction), Array)
    #12 C:EasyPHP-Webserver-14.1b2wwwcontestsyiiframeworkwebCWebApplication.php(282): CController->run(‘relationsAndAtt…’)
    #13 C:EasyPHP-Webserver-14.1b2wwwcontestsyiiframeworkwebCWebApplication.php(141): CWebApplication->runController(‘reports/default…’)
    #14 C:EasyPHP-Webserver-14.1b2wwwcontestsyiiframeworkbaseCApplication.php(169): CWebApplication->processRequest()
    #15 C:EasyPHP-Webserver-14.1b2wwwcontestsappprotectedcorecomponentsWebApplication.php(88): CApplication->run()
    #16 C:EasyPHP-Webserver-14.1b2wwwcontestsappindex.php(70): WebApplication->run()
    #17 {main}

    any assistance?