Plugin Use Cases/Add a Page to the Admin Theme

The following use case leads you through the creation of a plugin that adds a page to the admin theme, as well as on your public Omeka site.

Files You'll Create in this Use Case

  • CustomAdminPage/ (top-level plugin folder)
    • controllers/ (folder)
      • IndexController.php
    • plugin.ini
    • plugin.php
    • views/ (folder)
      • shared/ (folder)
        • index/ (folder)
          • foo.php

The Basics

Like any plugin, this one needs to have a plugin.php file and a plugin.ini file in its top-level directory.

Create a Controller

To add any new page, admin or public, to Omeka, you need to create a new controller, a PHP class that tells Omeka what to do when a user visits that page.

Each controller has its own PHP file. In a plugin, controllers go (predictably) in the controllers folder.

Create a View

To actually display a page, each action in a controller needs a view. A view is a simple PHP script that determines the HTML that will be output for the page.

Like controllers, each view goes in its own PHP file. For a plugins, views are stored in the views directory. There is a little added complication here, because a view can go in one of three possible directories under views:

  • views/admin: Views stored here will only be used on the admin side of the site.
  • views/public: Views stored here will only be used on the public side of the site.
  • views/shared: A view here will be used for both the admin and public sides. If a page should display exactly the same information on the admin and public sides, this is probably a good place for it.

For this example, we'll create a shared view, so the same view will display a page on the admin and public sides of the site. Once you've decided whether your view will be admin, public, or shared, the specific location where the view needs to go depends only on the name of the controller and the action that this view is for. The controller name becomes the subdirectory name, and the action name becomes the name of the view script itself.

Since we're creating a view for the fooAction of the IndexController, we want to create our view at views/shared/index/foo.php.