From: Demian K. <dem...@vi...> - 2018-03-12 13:30:28
|
You probably do need a controller; the question is simply where to put it. You have two basic options: 1. Create a separate OverdriveController for your Overdrive-specific actions. 2. Create some Overdrive-specific actions in the AjaxController. Right now, the AjaxController is a bit of a mess, with too many unrelated functions all coexisting in a single class; I’m currently in the process of refactoring it to make things a bit cleaner (see https://github.com/vufind-org/vufind/pull/1138 for my early work in progress). I think the separate OverdriveController probably makes the most sense for you in this context, but if you find yourself having to reinvent wheels from the AjaxController to achieve your results, the second option may turn out to be better. Anyway, I would suggest starting here: 1. Create a new VuFind\Controller\OverdriveController that extends VuFind\Controller\AbstractBase, and put an exampleAction() on it as a public method. 2. You can now add a static route here: https://github.com/vufind-org/vufind/blob/master/module/VuFind/config/module.config.php#L629 (by adding the string ‘Overdrive/Example’ to this array, you’ll automatically set up an /Overdrive/Example URL under the VuFind base URL, and a named ‘overdrive-example’ route that you can reference in templates In order to obtain the correct URL path). Obviously you can replace “Example” with some more meaningful action name. Once that’s done, you can access the record driver from inside the controller action by retrieving it using the record loader. Assuming you pass a record ID through a get parameter called ID, the code could look something like this: $id = $this->params()->fromQuery(‘id’); $driver = $this->serviceLocator->get(‘VuFind\Record\Loader’)->load($id); (Note that this is assuming you’re working against master… if you’re on earlier code, the service locator retrieval may look like $this->getServiceLocator()->get(‘VuFind\RecordLoader’)->load($id) instead). I hope that helps you move forward a little. If you run into any trouble, let me know – I’m working from memory here, so it’s possible I’ve led you slightly astray somewhere. If so, I want to get you back on course as soon as possible! - Demian From: Brent Palmer [mailto:Bre...@ic...] Sent: Sunday, March 11, 2018 1:14 PM To: Demian Katz <dem...@vi...> Cc: vuf...@li... Subject: Re: controller route config That is pretty much exactly where I am. I have records indexed as overdrive (lowercase). I have a record driver that extends the SolrDefault that is working fine. I can show overdrive availability. I am now working on ajax functionality that is not on one of the tabs. There is a button on the core template for either checking out or holding a title (depending on availability). I was just sort of trying to match the existing UX for putting a hold on a title with the lightbox popup. (It's also similar to our current catalog). I assumed I need to map that to actions on a controller somehow. For example a hold action and a checkout action. Although as I write this I'm realizing that I'm not sure how I call methods in my record driver to handle the checkout etc. So based on that should I proceed with a controller or can I avoid that somehow. Thanks for the help! Brent On Mar 11, 2018 9:29 AM, Demian Katz <dem...@vi...<mailto:dem...@vi...>> wrote: Brent, If your Overdrive records are sharing the biblio Solr core with your other records, you probably don't need a separate controller at all. The standard RecordController will be used for all of the biblio core records. It will load different tabs based on the settings here: https://github.com/vufind-org/vufind/blob/master/module/VuFind/config/module.config.php#L509<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fvufind-org%2Fvufind%2Fblob%2Fmaster%2Fmodule%2FVuFind%2Fconfig%2Fmodule.config.php%23L509&data=02%7C01%7Cdemian.katz%40villanova.edu%7C5a7abbd4a1584a28d0a708d587736bca%7C765a8de5cf9444f09cafae5bf8cfa366%7C0%7C0%7C636563852163800699&sdata=JOThpY%2FrsRGCT01ZW6jWEBmf1Y9xuMtRA3HdaJO%2FmIw%3D&reserved=0> I think what you may actually want is to set recordtype to "Overdrive" when indexing the records, define a SolrOverdrive record driver extending SolrDefault, and configure a custom tab list for the SolrOverdrive record. Your Overdrive-specific holdings functionality can go into an Overdrive-specific RecordTab plug-in. If you need to create some special AJAX actions, you may want to create a controller to house those, but I don't think you need to build a whole Overdrive-specific record controller. Does that help? - Demian ________________________________ From: Brent Palmer <Bre...@ic...<mailto:Bre...@ic...>> Sent: Saturday, March 10, 2018 7:11 PM To: vuf...@li...<mailto:vuf...@li...> Subject: [VuFind-General] controller route config Hi, I'm trying to wire together a controller for my Overdrive feature. I think I'm close but just can't seem to get it. The route config is not quite right. I'm not sure what information will be helpful so I'll throw some in down below and hope that is enough. My record type is "overdrive" and the records are in Solr. I don't have a separate backend. The task I'm working on is showing hold information on the lightbox popup. My record driver returns a RealTimeTitleHold that looks like this: "/catalog/OverdriveRecord/$rec_id/hold"; I have a OverdriverecordController with the constructor and a holdAction. The searchClassId is set to "OverdriveRecord" The holdAction sets the template: $view->setTemplate('RecordDriver/SolrOverdrive/hold'); (there is a template there that just says hello) In module.config I have the controller configured like so in the controller factories array: 'overdriverecord' => 'VuFind\Controller\Factory::getOverdriverecordController', I have the record route configured like so down below in $recordRoutes: 'overdriverecord' => 'OverdriveRecord', The error I get when I try to show the lightbox is: "VuFindSearch\Exception\RuntimeException : Unable to resolve backend: retrieve, OverdriveRecord" I've tried setting the searchClassId to various things but I get the same error. Thanks! Brent |