Forums » Adding Custom Controller to Theme

RSS feed for this topic

Info

  1. Hi,

    I'm trying to add my own controller to a custom theme and would appreciate any guidance or code examples on how to do this.

    More specifically, I want to generate a URL which will allow the client to download a file from the database using an ID from the omeka_files table:

    /file/download/123

    I then what the code to redirect to the actual file:

    /archive/files/filename.ext

    I'm happy to implement this into a plugin if required.

    Many Thanks
    Stephen

  2. Have you seen this thread about returning file URLs on items/show pages?

    http://omeka.org/forums/topic/need-function-to-return-only-the-file-url

  3. Hi Sheila,

    I have seen that but it's unfortunately not what I'm looking for.

    I'm going to be storing omeka_files.id values in an external database so that I can access the file directly and not via /items/show/.

    I would prefer to use omeka_files.id value and not omeka_files.archive_filename value incase this value changes.

    Many Thanks
    Stephen

  4. Does anyone else know how to add their own Controller definitions?

  5. Hi Stephen,

    A plugin would be required for this. Off the top of my head, I think creating a Controller in your plugin that extends the FileController, with a downloadAction, would do the trick. The action could then redirect to actually download or display the file attached to the File record.

    This should be able to work with the way Omeka currently constructs routes, defined in application/config/routes.ini.

    Best,
    Jeremy

  6. After discussing with another developer, it would actually be better to do this as a plugin with it's own custom Controller, that extends Omeka_Controller_Action. You'd still create the downloadAction to do the actual downloading, but you'd also need to create a route for files/download/:id.

    We actually used to have something similar in an earlier version of Omeka, but removed it for performance reasons. Basically, you'd have to load Omeka each time you call that URL, instead of simply serving the file through Apache.

  7. Hi Jeremy,

    I just want to public say thank you with your help via email.

    The link to the Zend documentation is a great help and I'm just reading through it now.

    Many Thanks
    Stephen

  8. Guess I should just post this here! I was a bit curious how to write such a plugin, so I created one that folks can view. It's very basic, and probably won't be a tagged release, but its available should anyone want to use it as a base for some other plugin. If anyone does something with it, let us know!

Reply

You must log in to post.