A few things I noticed just at first glance:
- It looks like you don't need your ItemsController. Your custom route is redirecting to your IndexController, and that's the one you wrote your view script for also.
- You have some written-out SQL for determining the ID of the Dublin Core Subject element, and this is included in your plugin.php file. This means that query is going to run on every page load in Omeka for users who have this plugin installed. If you do want to do a separate query for this, I would consider moving it to your IndexController's indexAction.
- On sort of the same subject, Omeka generally tries to conform to the MVC pattern throughout, so we'd generally discourage running an SQL query in your view script. You could page through the subjects and build out an array of the links you want to display, and have your view script act only on that array.
As for your question about your custom route, it looks like you've pretty much got it right. The define_routes code you have correctly adds a new custom route at items/subject-browse which points to your plugin. The reason you're still able to go to /subject-browse is because Zend's (and Omeka's) default route includes a route that matches against your module. So, /subject-browse matches your IndexController's indexAction, and adding your new route doesn't remove the default one.
-John
> --
> You received this message because you are subscribed to the Google Groups "Omeka Dev" group.
> To post to this group, send email to omek...@googlegroups.com.
> To unsubscribe from this group, send email to omeka-dev+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/omeka-dev?hl=en.
>
PHP's define is only going to make a definition persistent for one request (though this may be different with some PHP caching systems like APC).
Personally, I think your best bet at the moment would be to include both queries in your controller action code. This gives you the benefit of not running that subject id query on requests that don't need it, and moves your other query out of your view. If you really want to run that check about the subject id only once, you could run the query in your install hook and set an option in the Omeka DB with set_option. Afterwards, you could use get_option to get that id to create your query.
I don't think you do need a model class for this. There's a school of thought that would be more militant about keeping SQL out of the controller code, but I don't necessarily subscribe to that. For better or worse, models generally arise in Omeka plugins when the plugin is creating its own tables in the database.
On the topic of your "real" query, the one that's in your view right now, I've taken a closer look at it, and it looks to me like it's a little over-complex. You're only retrieving the 'text' column from the ElementTexts table, but you're also joining against the ElementSets and Elements tables. That initial query you're doing to determine the Subject element ID allows you to skip those extra joins entirely. When you're not dealing with Item Types, a particular element ID uniquely describes a particular element of a particular set. All you should need to do is select from the ElementTexts table where element_id = (the id you determined earlier).
Have you considered making an admin view for this as well? This could also be a convenient way for admins to look through their items.
-John
> I'm a little stuck on how to make a variable created in the
> indexAction accessible from the view.
From the action method, you should be able to do:
$this->view->variableName = $whatever;
Then you will have access to $variableName in your view script.
> It seems to me that using the set/get option mechanic is probably not
> a performance win, at least not if that option is coming from the
> database. I don't know where option values live when they're home, so
> to speak - in any case, that's more optimization than I should
> probably be doing at this stage of development.
Normally you'd be right on this fact, but since Omeka uses so many options on every request, it already reads the whole options table into an array.
So, getting an option is really just an array access, it doesn't incur an extra query.
-John