api_resources filter and plugin controller search path

26 views
Skip to first unread message

Sarah Weissman

unread,
Jan 20, 2016, 1:59:55 PM1/20/16
to Omeka Dev

Hi devs,

I am new to Omeka and I'm trying to write a plugin (working in Omeka 2.3) that creates a new API resource that will look up items by their DC IDs. To do this I'm creating an api_resources filter that defines a new controller for an Item. The problem I'm having is that Omeka doesn't seem to find my controller. I created a class called Omekaapiextension_ItemController located in controllers/api/ItemController.php in my plugin folder. My filterApiResources is:

public function filterApiResources($apiResources)
{
    $apiResources['my_item'] = array(
        'module' => 'OmekaAPIExtension',
        'controller' => 'item',
        'record_type' => 'Item',
        'actions' => array(
            'get', 
        ),
    );
    return $apiResources;
}

When I try to access "api/my_item/1" I am getting an error {"message":"Invalid controller specified (item)"}. I dug into the code and it seems like this is happening because Omeka is not searching the controller directory of my plugin when it's looking to see if the controller is defined. If I manually add the following lines to filterApiResources:

    $front = Zend_Controller_Front::getInstance();
    $front->addControllerDirectory('<PATH TO OMEKA>/plugins/OmekaAPIExtension/controllers','OmekaAPIExtension');

then the controller is found. So I assume there is some setting I'm missing somewhere to define where Omeka should look for the controller, but I can't find any documentation or examples that show how to do this configuration, so i'm hoping someone on the list can help out. I've been following the instructions for extending the API (http://omeka.readthedocs.org/en/latest/Reference/api/extending.html), but there is only info there on using the default controller.

Thanks,
Sarah

John Flatness

unread,
Jan 20, 2016, 5:30:31 PM1/20/16
to Omeka Dev
As long as the "controllers" directory exists for a plugin, Omeka already automatically adds that as a controller directory for the plugin's module. That's what makes normal controllers load for plugins already.

I think, just as a guess, it's possible that the problem here is a simple one: the module name you need to use, like the controller, is lowercase and separated by dashes. By manually registering the controller directory with an also CamelCased module name, you worked around the issue. So, I think if the module value had been "omeka-api-extension" when you used it in filterApiResources, you wouldn't need the addControllerDirectory call.

-John

Sarah W

unread,
Jan 21, 2016, 9:47:14 AM1/21/16
to omek...@googlegroups.com
Thanks! That appears to have been the problem.  I'm still getting used to these naming conventions.

--
You received this message because you are subscribed to the Google Groups "Omeka Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omeka-dev+...@googlegroups.com.
To post to this group, send email to omek...@googlegroups.com.
Visit this group at https://groups.google.com/group/omeka-dev.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages