Adding Custom Controller to Theme


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:


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


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

Many Thanks

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

Hi Sheila,

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

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

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

Many Thanks

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

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.


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.

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

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!