Warning: This page has not been updated in over over a year and may be outdated or deprecated.
videos:code_generators_1
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
videos:code_generators_1 [2020/10/13 13:38] – [Transcript] demiankatz | videos:code_generators_1 [2023/04/26 13:31] (current) – crhallberg | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Video 11: Code Generators, Part 1: Setting Up/Creating a Recommendation Module ====== | ====== Video 11: Code Generators, Part 1: Setting Up/Creating a Recommendation Module ====== | ||
- | The eleventh | + | The eleventh |
Video is available as an [[https:// | Video is available as an [[https:// | ||
Line 13: | Line 13: | ||
===== Transcript ===== | ===== Transcript ===== | ||
- | // This is a raw machine-generated transcript; it will be cleaned up as time permits. // | + | Welcome to the 11th VuFind tutorial video. |
- | | + | So before we start creating a code module, let me just talk a little bit about code modules in general. So if I go to the VuFind |
- | video | + | |
- | uh this month we are going to look start | + | The modules that come with VuFind |
- | looking at code generators | + | |
- | uh and talk about how to manage local | + | So I'm just going to, from my VuFind |
- | custom code and how to build | + | |
- | a simple recommendation module using a | + | Now it asks me what module name I want to use and this is where I need to make a decision. There can be any legal PHP namespace, which means practically anything. You just want to be careful that you don't choose a name that either conflicts with an internal |
- | code generator | + | |
- | so in past videos we've talked about two | + | So all that the installer has done is it's created the empty local module for me, and it has updated my Apache |
- | ways in which you can customize your | + | |
- | viewfind instance | + | I'm going to get add the changes to my env.bat. |
- | one by maintaining a local configuration | + | |
- | directory for your config files and | + | There are a couple more things that I also am going to need to do to fully prepare this module. First of all, because |
- | another by creating a local theme | + | |
- | so the third way is to create a local | + | The other thing I want to do is be sure that I have my module defined as an environment variable at the command line. Because |
- | code module | + | |
- | where you can extend override | + | But before |
- | or add to viewfinds code | + | |
- | so before we start creating a code | + | Then under config there' |
- | module let me just talk | + | |
- | a little bit about code modules in | + | Thus, we need to add some code. And VuFind |
- | general | + | |
- | so if i go to the viewfind | + | So I'm going to call this recommendation module tutorial recommend combined notes. So, we'll go back to this generate command and we will say '' |
- | directory | + | |
- | and i look at the files that are here uh | + | The next part is " |
- | there's a directory called module | + | |
- | and if i look in there i see that there | + | The reason |
- | are | + | |
- | a number of subdirectories you find you | + | Anyway, |
- | find api | + | |
- | you find admin etc | + | And going into depth on how this whole service manager configuration works would be a good topic for a future video. But for now, just take for granted that the generator configured this all correctly for you so that you don't have to worry about it. You can just fill in this class and this factory and use this alias name in your configuration files. |
- | uh each of these directories is a | + | |
- | lominos | + | So let's look at the source that was generated. These are combined notes.php. As you can see it has the right tutorial recommend |
- | laminas | + | |
- | allows you to organize your code into | + | For today' |
- | modules each of which is bundled | + | |
- | with a bit of configuration | + | So I'm going to go into my local config directory. Into combined |
- | and a laminas | + | |
- | by composing together | + | Let me quickly show you how to turn on development mode. I'm going to edit the Apache |
- | a number of these modules | + | |
- | get all of the functionality into one | + | Can't find it, therefore it can't display recommendations and it throws an error. And so, this points out that by convention, every recommendation module needs to have a PhDML file in the recommend template directory of your team, whose name corresponds with the name of the class. Any VuFind |
- | place | + | |
- | and the neat thing about the code plus | + | Now the important thing is, in order to proceed, we need to create this template file. And because |
- | configuration design here | + | |
- | is that you can add a module of your own | + | This would be a really good time to go back to the command line and commit all of this stuff that I have just done. So I'm going to get add module tutorial source. And I'm going to get add this tutorial templates. And I'm going to commit that as create combined notes recommendation module. I can also get add my HTTP VuFind |
- | and load it last | + | |
- | and then the configuration of your | + | So at this point I've already demonstrated how to set up a local module, how to use a plugin |
- | module will override | + | |
- | equivalent configuration in any of the | + | But it would be more fun to see how all the different pieces work together. So let's start by adding a configuration setting so that if we want to change the name of our combined search results, we can set that in the i and i file. As I mentioned earlier, the set config method of a recommendation module allows you to receive configuration settings that come from the i and i. So if I open up my combined notes. Let's create a protected property here called name. And then in set config. Let's just pass the settings we receive into that name property. And let's create a new public method called get name, which simply returns that name property that I just set up. So now, I'm going to go to combined i and i. I can add parameters to a recommendation module by just putting in a colon and then adding stuff after the colon. So, let's say the tutorial results, put this whole thing in double quotes since it has spaces in it. We want to be sure the configuration parses correctly. The tutorial results will get passed to the set config method. Then it will get stored in the this name property and it will be available for retrieval through this public get name method. And of course, the place where we want to retrieve it is in our template, which by convention is going to have access to our. CombinedNotes |
- | earlier | + | |
- | thus you can build your own module for | + | So now I come back here and I refresh the page. Combined |
- | viewfind | + | |
- | put your code and configuration in there | + | Let's just do one more clever thing and show the user's search query along with the message. We can do that by going to be going to the process method, which receives an instance of VuFind |
- | and this gives you the power to add to | + | |
- | or replace any of the core functionality | + | Of course, |
- | the modules that come with viewfind | + | |
- | bundle different parts of its | + | |
- | functionality | + | //This is an edited version of an automated transcript. Apologies for any errors.// |
- | application is in the main | + | |
- | viewfinder | + | |
- | pieces have been broken out into | + | |
- | separate chunks | + | |
- | and it's entirely possible that over | + | |
- | time the code will become more modular | + | |
- | as we split it up into more logical | + | |
- | pieces | + | |
- | but that's an ongoing process | + | |
- | case | + | |
- | um to get started let's create a local | + | |
- | module | + | |
- | where we can begin to work and when i | + | |
- | create it i' | + | |
- | looks like so you can have a better | + | |
- | understanding of how these modules | + | |
- | are structured | + | |
- | if you want a module | + | |
- | install script | + | |
- | gives you an option to create one so | + | |
- | depending on how you set up your | + | |
- | viewfind | + | |
- | instance you might actually already have | + | |
- | one but if you don't | + | |
- | don't worry you can just run the | + | |
- | installer again | + | |
- | keep all of your options the same except | + | |
- | add a module | + | |
- | and that' | + | |
- | exactly what i'm going to do | + | |
- | right now the tutorial | + | |
- | viewfinder | + | |
- | with was installed from a debian | + | |
- | which does not create a local code | + | |
- | module by default | + | |
- | so i'm just going to from my viewfind | + | |
- | home directory | + | |
- | run php phpinstall.php | + | |
- | to re-run | + | |
- | give me the option | + | |
- | to create a module | + | |
- | sure that | + | |
- | all of the other choices | + | |
- | the same as the choices that were made | + | |
- | the last time | + | |
- | the installer was run so it asks me | + | |
- | where i want my local settings | + | |
- | of viewfind | + | |
- | keep the default | + | |
- | now it asks me what module name i want | + | |
- | to use and this is where i need to make | + | |
- | a decision | + | |
- | your module name can be any legal php | + | |
- | namespace | + | |
- | which means practically anything | + | |
- | just want to be careful that you don't | + | |
- | choose | + | |
- | a name that either conflicts with an | + | |
- | internal | + | |
- | or conflicts with an existing | + | |
- | module | + | |
- | or any of ufind' | + | |
- | usually | + | |
- | local institution | + | |
- | you'll be very safe for the purposes of | + | |
- | the tutorial | + | |
- | though | + | |
- | module tutorial | + | |
- | so now it asks me what path to use in | + | |
- | viewfind' | + | |
- | i want to keep that the same slash | + | |
- | viewfind | + | |
- | and i'm done so all that the installer | + | |
- | has done | + | |
- | is it's created the empty local module | + | |
- | for me | + | |
- | and it has updated my apache | + | |
- | configuration | + | |
- | to include a setting to load that module | + | |
- | so since we got viewfind | + | |
- | control last week | + | |
- | or rather last month i can do git status | + | |
- | to see what the installer actually did | + | |
- | and as i can see it has created | + | |
- | a module tutorial | + | |
- | directory | + | |
- | my environment.that file which i don't | + | |
- | care about because that only is used | + | |
- | under windows | + | |
- | and my local httpd | + | |
- | viewfinder.com my apache | + | |
- | so let me do a quick get diff to inspect | + | |
- | exactly what has changed | + | |
- | so first of all what happened in the | + | |
- | environment that | + | |
- | which again doesn' | + | |
- | not in windows | + | |
- | we would care that it has added an | + | |
- | environment variable | + | |
- | uh pointing | + | |
- | important changes | + | |
- | are in the apache | + | |
- | where you can see that it has | + | |
- | uncommented | + | |
- | the setting to set up the viewfind | + | |
- | modules environment variable and set | + | |
- | it to tutorial | + | |
- | tells viewfind | + | |
- | code to load there' | + | |
- | change up here | + | |
- | where a comment has changed and that' | + | |
- | simply a side effect of having | + | |
- | upgraded viewfind to a newer version | + | |
- | that no longer mentions | + | |
- | zen framework a harmless side effect of | + | |
- | re-running the installer | + | |
- | so if i had made any mistakes when | + | |
- | running the install.php | + | |
- | script | + | |
- | changes in here | + | |
- | like changes to viewfind' | + | |
- | path | + | |
- | uh so if that had happened | + | |
- | done a get reset | + | |
- | to back out the changes and i could try | + | |
- | again | + | |
- | but in this case i've gotten it right | + | |
- | the first time | + | |
- | so i am just going to commit these | + | |
- | changes | + | |
- | so that i have all of this going forward | + | |
- | so i'm going to do a gift status again | + | |
- | to see what i'm working with | + | |
- | i'm going to git add the changes to my | + | |
- | env.bat | + | |
- | viewfinder.com and i'm going to add my | + | |
- | new | + | |
- | tutorial module i'm also going to | + | |
- | delete this httpd | + | |
- | viewfinder.com.back.timestamp | + | |
- | file that's a backup that the install | + | |
- | script made | + | |
- | of my apache | + | |
- | really nice safety mechanism to have | + | |
- | if you're not using git but since we're | + | |
- | using git to manage our changes in our | + | |
- | our versioning we really don't need to | + | |
- | keep backup files around | + | |
- | using git if we really have to so i'm | + | |
- | going to commit | + | |
- | add tutorial module | + | |
- | there are a couple more things that i | + | |
- | also am going to need to do | + | |
- | to fully prepare this module | + | |
- | first of all because | + | |
- | apache | + | |
- | i need to restart | + | |
- | configuration | + | |
- | so i can do that with sudo system ctl | + | |
- | restart apache | + | |
- | and i'm just going to go over to my web | + | |
- | browser and refresh my viewfinder | + | |
- | confirm that | + | |
- | it still works i haven' | + | |
- | everything by adding my | + | |
- | new module | + | |
- | want to do | + | |
- | is be sure that i have my module defined | + | |
- | as an environment variable at the | + | |
- | command line | + | |
- | because | + | |
- | utilities | + | |
- | my custom code | + | |
- | as well so i do this by editing | + | |
- | the etc.profile.d | + | |
- | viewfind.sh script | + | |
- | that | + | |
- | export | + | |
- | tutorial | + | |
- | uh then i'll reload | + | |
- | my profile | + | |
- | and now if i | + | |
- | echo dollar viewfind underscore local | + | |
- | underscore modules i get tutorials | + | |
- | environment variables are all set up | + | |
- | and i'm ready to begin working with this | + | |
- | module | + | |
- | but before | + | |
- | take a quick look | + | |
- | at what's actually in there | + | |
- | and i'll actually open up vs code | + | |
- | to do that because | + | |
- | easier to look at in a code editor | + | |
- | all right so here i am in vs code | + | |
- | and if i look under my module directory | + | |
- | i see all of | + | |
- | viewfind' | + | |
- | tutorial module | + | |
- | i've created if i expand that out i see | + | |
- | we have a few things here we have a | + | |
- | module.php file | + | |
- | every laminas module contains a | + | |
- | module.php | + | |
- | which is used for loading the module | + | |
- | if we look at this file | + | |
- | there's not a whole lot in here uh it | + | |
- | loads the configuration file for us | + | |
- | it sets up an autoloader | + | |
- | the rest of the framework knows where to | + | |
- | find the code that lives in the module | + | |
- | and it has a couple of empty hook | + | |
- | methods where you could theoretically | + | |
- | add | + | |
- | actions that occur when the module | + | |
- | initializes or bootstraps but you rarely | + | |
- | need to do that | + | |
- | so this is a file you shouldn' | + | |
- | touch much it's just | + | |
- | part of the setup of the module | + | |
- | under config there' | + | |
- | file containing the modules | + | |
- | configuration | + | |
- | right now this is simply an empty array | + | |
- | uh because we haven' | + | |
- | here yet | + | |
- | but we could in theory | + | |
- | configuration from other modules and | + | |
- | change it | + | |
- | and it would be overridden because our | + | |
- | tutorial module is going to load last | + | |
- | which makes it take precedence over the | + | |
- | things that are loaded before it | + | |
- | and finally we have a source | + | |
- | slash tutorial | + | |
- | where all of our code will live | + | |
- | but we haven' | + | |
- | module yet so right now | + | |
- | it's simply an empty directory | + | |
- | thus uh we need to add some code | + | |
- | and viewfind | + | |
- | code generator tools | + | |
- | that can be used to add code to a local | + | |
- | module | + | |
- | today we're going to look specifically | + | |
- | at the plug-in | + | |
- | which is what you use when you want to | + | |
- | create a new plugin | + | |
- | of an existing type so | + | |
- | to run the plug-in | + | |
- | simply run | + | |
- | php viewfind home | + | |
- | slash public | + | |
- | space generate | + | |
- | some parameters | + | |
- | but with any of you finds command line | + | |
- | tools if you don't | + | |
- | know what the parameters are you can add | + | |
- | minus minus help | + | |
- | and you'll get a usage screen | + | |
- | so this shows us that we can provide | + | |
- | the plug-in | + | |
- | the class we want it to generate and | + | |
- | optionally the name of the factory that | + | |
- | we want to use to instantiate our class | + | |
- | when viewfind | + | |
- | specify | + | |
- | a factory the generator will actually | + | |
- | create a new factory for you | + | |
- | that will generate an instance of your | + | |
- | class | + | |
- | there's also an optional top level | + | |
- | switch | + | |
- | that you can use if you want to create a | + | |
- | plugin | + | |
- | in viewfind' | + | |
- | otherwise | + | |
- | at the class name you provided it and | + | |
- | try to figure out | + | |
- | what kind of plugin you're generating | + | |
- | based on the name space and then put it | + | |
- | in the appropriate context | + | |
- | so as i mentioned at the beginning what | + | |
- | we're going to generate today | + | |
- | is a recommendation module | + | |
- | about recommendation modules | + | |
- | quite a few videos ago when we were | + | |
- | talking about search configuration | + | |
- | so recommendation modules can be turned | + | |
- | on in the ini files | + | |
- | and they provide additional information | + | |
- | usually above or to the side of search | + | |
- | results | + | |
- | today what i'm going to do is create a | + | |
- | recommendation module that will display | + | |
- | a message at the top of the combined | + | |
- | search screen | + | |
- | so this shows you how if you wanted to | + | |
- | put a welcome message | + | |
- | or some kind of additional local | + | |
- | information | + | |
- | you could easily add it to that top | + | |
- | level screen | + | |
- | so i'm going to call this recommendation | + | |
- | module | + | |
- | tutorial recommend combined notes | + | |
- | so we'll go back to this | + | |
- | generate command and we will say php | + | |
- | if you find home public index.php | + | |
- | generate plugin | + | |
- | tutorial backslash backslash recommend | + | |
- | backslash backslash | + | |
- | combined notes i'm not going to specify | + | |
- | a factory so this will allow it to | + | |
- | generate one for us | + | |
- | and a couple of notes about what i've | + | |
- | done here so | + | |
- | i want to create a class called tutorial | + | |
- | recommend | + | |
- | combined notes each part of this is | + | |
- | important | + | |
- | the tutorial | + | |
- | the first part of the namespace | + | |
- | tells the viewfinder | + | |
- | what module this belongs to | + | |
- | everything | + | |
- | needs to live inside the tutorial module | + | |
- | and all code in the tutorial module | + | |
- | needs to belong to the tutorial | + | |
- | namespace | + | |
- | the next part is recommend | + | |
- | all of our recommendation modules have | + | |
- | the second part of their namespace set | + | |
- | to recommend | + | |
- | so most of you finds core recommendation | + | |
- | modules have classes that are named | + | |
- | viewfind | + | |
- | backslash recommend backslash | + | |
- | so we're following that same pattern | + | |
- | we're just using our tutorial | + | |
- | and of course | + | |
- | of the actual class we want to create | + | |
- | within this namespace | + | |
- | the reason | + | |
- | backslashes | + | |
- | is because backslashes are how fully | + | |
- | qualified | + | |
- | uh represent the parts of or connect | + | |
- | together the parts of a namespace | + | |
- | but backslashes | + | |
- | on the linux command line | + | |
- | so i have to double them up so that they | + | |
- | get passed through correctly to the php | + | |
- | code | + | |
- | if i only put single backslashes here | + | |
- | weird stuff would happen | + | |
- | so that's a common gotcha | + | |
- | you're providing class names | + | |
- | to generators that you double up all the | + | |
- | backslashes | + | |
- | anyway | + | |
- | see some messages | + | |
- | it created my combined notes class it | + | |
- | created a combined | + | |
- | it backed up my module configuration and | + | |
- | then it updated | + | |
- | the module configuration | + | |
- | so if i do a git status now | + | |
- | i see that some files have been added | + | |
- | to my module tutorial source directory | + | |
- | and my module configuration has been | + | |
- | modified | + | |
- | i'm going to switch back over to vs code | + | |
- | to just | + | |
- | show you uh what we've got so as you can | + | |
- | see my module configuration | + | |
- | has gotten some stuff added to it | + | |
- | there's now a plugin | + | |
- | inside of you find array and it contains | + | |
- | a recommend section which is where | + | |
- | recommendation modules | + | |
- | are defined | + | |
- | factories element which specifies | + | |
- | that this new tutorial recommend | + | |
- | combined | + | |
- | notes class that i created should be | + | |
- | built | + | |
- | by the combined notes factory | + | |
- | additionally | + | |
- | there's an alias set up so that when i | + | |
- | configure in my configuration files | + | |
- | a recommendation module named combined | + | |
- | notes it knows that that | + | |
- | maps to uh the combined notes class that | + | |
- | we've just created | + | |
- | and going into depth on how this whole | + | |
- | service manager configuration works | + | |
- | would be a good topic for a future video | + | |
- | but for now uh just take for granted | + | |
- | that | + | |
- | the generator configured this all | + | |
- | correctly for you so that you don't have | + | |
- | to worry about it | + | |
- | you can just fill in this class and this | + | |
- | factory | + | |
- | and use this alias name in your | + | |
- | configuration files | + | |
- | so let's look at the source that was | + | |
- | generated | + | |
- | first of all here's our | + | |
- | combinednotes.php | + | |
- | as you can see it has the right tutorial | + | |
- | recommend | + | |
- | it's named combined notes it implements | + | |
- | the appropriate interface for a | + | |
- | recommendation module | + | |
- | which the generator figured out based on | + | |
- | the namespace | + | |
- | we told it to use when we specified our | + | |
- | class name | + | |
- | but there' | + | |
- | to have to write this class | + | |
- | we'll get there in a moment but first | + | |
- | let's take a look at the factory that | + | |
- | was created | + | |
- | and all this does | + | |
- | is return an instance of the | + | |
- | requested service which based on the way | + | |
- | the service manager works is always | + | |
- | going to be | + | |
- | the name of the class that we want to | + | |
- | build which would be | + | |
- | tutorial recommend combined notes | + | |
- | uh based on what we're doing today there | + | |
- | is actually no reason to build | + | |
- | a special factory to generate this i | + | |
- | just wanted to demonstrate that it's | + | |
- | possible | + | |
- | so that if you're building something | + | |
- | with dependencies you have this class | + | |
- | available | + | |
- | injection | + | |
- | within | + | |
- | going to leave this at the default | + | |
- | and not worry about it any further | + | |
- | so because | + | |
- | implements an interface we're not going | + | |
- | to be able to | + | |
- | use it until we've defined all of the | + | |
- | methods that the interface | + | |
- | requires | + | |
- | about | + | |
- | the recommendation module interface | + | |
- | and how it works so in vs code i can | + | |
- | take advantage of the fact that i can | + | |
- | right click on well normally | + | |
- | all right that's not working | + | |
- | i need to look up this viewfind | + | |
- | recommend recommend interface to see | + | |
- | exactly | + | |
- | what methods | + | |
- | local class | + | |
- | and as i mentioned our namespace | + | |
- | us what module our code lives in so i | + | |
- | know that this is defined in the meme | + | |
- | you find module under the source | + | |
- | directory | + | |
- | so here's the view find namespace | + | |
- | recommend | + | |
- | and recommend interface | + | |
- | so a php interface just defines which | + | |
- | methods | + | |
- | a class needs to define | + | |
- | to copy and paste | + | |
- | all of these method definitions from the | + | |
- | interface | + | |
- | my new combined notes class | + | |
- | and for starters | + | |
- | them all | + | |
- | empty methods that don't do anything | + | |
- | there are three methods that | + | |
- | recommendation modules have to define | + | |
- | the first is set config which receives | + | |
- | extra configuration settings that the | + | |
- | user defines | + | |
- | in the any file and makes use of them so | + | |
- | we can leave this empty if we don't have | + | |
- | any | + | |
- | configuration | + | |
- | method | + | |
- | which gets called before | + | |
- | search but after | + | |
- | the user's search request has been | + | |
- | processed | + | |
- | so if we want a recommendation module to | + | |
- | analyze | + | |
- | user input or actually make changes to | + | |
- | the | + | |
- | request that we're going to make we can | + | |
- | do that here | + | |
- | this is not done very often but for | + | |
- | example | + | |
- | the side facets recommend module uses | + | |
- | the init method | + | |
- | to turn on the facet values that the | + | |
- | user has configured | + | |
- | for today' | + | |
- | be touching | + | |
- | and finally there' | + | |
- | which gets called after the search has | + | |
- | been performed | + | |
- | and which can be used to extract | + | |
- | information from the search results if | + | |
- | we want to use that | + | |
- | to impact the message that we ultimately | + | |
- | display to the user | + | |
- | but it's perfectly valid to leave all of | + | |
- | this | + | |
- | empty uh and then you just have a | + | |
- | recommendation module that doesn' | + | |
- | anything | + | |
- | except display a template | + | |
- | so let' | + | |
- | see what happens | + | |
- | and spoiler alert it's not going to work | + | |
- | yet | + | |
- | because we haven' | + | |
- | just want to demonstrate | + | |
- | what this all looks like so i'm going to | + | |
- | go | + | |
- | into my local config | + | |
- | directory | + | |
- | into combined.ini | + | |
- | because | + | |
- | recommendation module at the top of my | + | |
- | combined search results | + | |
- | and at the bottom of combine.ini | + | |
- | a recommendation module section | + | |
- | that lets me turn these things on so i'm | + | |
- | going to put it on in the top | + | |
- | the name uh as you recall from the alias | + | |
- | that was generated in my configuration | + | |
- | is called combined notes | + | |
- | so just by adding this top equals | + | |
- | combined notes to the recommendation | + | |
- | modules list in combined.ini | + | |
- | i should now have turned on | + | |
- | my new recommendation module and it | + | |
- | should appear at the top of my combined | + | |
- | search results | + | |
- | except | + | |
- | created a template yet | + | |
- | but as you can see what i'm looking at | + | |
- | here is the generic | + | |
- | please contact us for help message which | + | |
- | doesn' | + | |
- | what went wrong | + | |
- | and that's because by default | + | |
- | viewfinder | + | |
- | which does not display detailed error | + | |
- | messages because we don't want to | + | |
- | accidentally display something | + | |
- | that exposes a security vulnerability to | + | |
- | the general public | + | |
- | however | + | |
- | developing | + | |
- | server | + | |
- | it's often helpful to turn on | + | |
- | development mode which will display | + | |
- | richer error messages when things like | + | |
- | this go wrong | + | |
- | let me quickly show you how to turn on | + | |
- | development mode | + | |
- | if i edit the apache | + | |
- | local | + | |
- | http viewfinder.com | + | |
- | and scroll down a little bit | + | |
- | there's a commented outline that says | + | |
- | set end | + | |
- | viewfinden | + | |
- | that | + | |
- | and then restart | + | |
- | apache | + | |
- | now viewfinder | + | |
- | and if i refresh this page | + | |
- | i get a much more useful message | + | |
- | which is actually telling me that | + | |
- | i didn't set up my recommendation module | + | |
- | correctly | + | |
- | that i didn' | + | |
- | changes over here | + | |
- | sure enough that's what happened | + | |
- | was originally complaining because | + | |
- | hadn't saved | + | |
- | my method definitions and so i wasn't | + | |
- | conforming to the interface | + | |
- | i've now gone back saved that and fixed | + | |
- | it so if i refresh again i should get | + | |
- | the next error message | + | |
- | which is now that it's looking for | + | |
- | a combined notes template so that it can | + | |
- | display the recommendations but i | + | |
- | haven' | + | |
- | can't find it therefore it can't display | + | |
- | recommendations | + | |
- | and it throws an error | + | |
- | and so this points out that by | + | |
- | convention | + | |
- | every recommendation module needs to | + | |
- | have a phtml | + | |
- | file in the recommend template directory | + | |
- | of your theme | + | |
- | whose name corresponds with the name of | + | |
- | the class | + | |
- | uh any viewfind | + | |
- | something follows this convention | + | |
- | of having a template directory | + | |
- | containing | + | |
- | correspond with class names | + | |
- | and if you look in the plugins page of | + | |
- | the viewfind | + | |
- | you'll find all of the plugin types you | + | |
- | can build | + | |
- | as well as notes on these types of | + | |
- | conventions on a plug-in | + | |
- | basis | + | |
- | but for now the important thing is in | + | |
- | order to proceed | + | |
- | we need to create this template file | + | |
- | and because | + | |
- | change core viewfind | + | |
- | turn on our custom theme again so that | + | |
- | we can | + | |
- | make our custom files in our custom | + | |
- | theme | + | |
- | so i'm just going to bring up | + | |
- | my config.ini file | + | |
- | in my local configuration directory | + | |
- | and i'm going to comment out the | + | |
- | bootprint 3 theme and | + | |
- | uncomment the tutorial theme that we set | + | |
- | up | + | |
- | a few months ago and now | + | |
- | inside | + | |
- | inside my tutorial theme inside its | + | |
- | templates directory | + | |
- | i'm going to create a new folder called | + | |
- | recommend | + | |
- | and inside that folder | + | |
- | create a new template file | + | |
- | called | + | |
- | and inside that file i'm just going to | + | |
- | put some html you | + | |
- | are looking at combined | + | |
- | and i will actually save that this time | + | |
- | so now if i go back to my browser and i | + | |
- | refresh the page | + | |
- | again everything is working | + | |
- | theme is turned on which is why things | + | |
- | look different | + | |
- | and my recommendation module has loaded | + | |
- | and rendered | + | |
- | right above my search results | + | |
- | this would be a really good time to go | + | |
- | back to the command line | + | |
- | and commit all of this stuff that i have | + | |
- | just done | + | |
- | so i'm going to git add module | + | |
- | tutorial source | + | |
- | add themes | + | |
- | and i'm going to commit that as create | + | |
- | combined notes recommendation module | + | |
- | i can also | + | |
- | get add my httpd viewfind | + | |
- | where i turned on development mode let's | + | |
- | say turned on development mode | + | |
- | and for now i'm not going to commit my | + | |
- | configuration changes | + | |
- | uh we'll see if we want to keep things | + | |
- | this way after we've | + | |
- | done a little bit more work so at this | + | |
- | point | + | |
- | i've already demonstrated how to set up | + | |
- | a local module how to use a plug-in | + | |
- | generator | + | |
- | to create a plug-in | + | |
- | how to turn that on and how to fill it | + | |
- | in enough that it will work | + | |
- | um but let's do a little bit more | + | |
- | advanced work | + | |
- | and talk a little bit more about | + | |
- | recommendation modules while we have | + | |
- | this opportunity | + | |
- | because it's great that we can display | + | |
- | this template in this place | + | |
- | but it would be more fun to see how all | + | |
- | the different pieces work together | + | |
- | so let's start by adding a configuration | + | |
- | setting | + | |
- | so that if we want to | + | |
- | change the name of our combined search | + | |
- | results | + | |
- | we can set that in the ini file | + | |
- | as i mentioned earlier | + | |
- | the set config method | + | |
- | of a recommendation module | + | |
- | uh allows you to receive configuration | + | |
- | settings | + | |
- | that come from uh the ini | + | |
- | so if i open up my combined notes | + | |
- | let's create a protected property here | + | |
- | called name | + | |
- | and then in set config | + | |
- | the settings we receive | + | |
- | into that name property | + | |
- | and let's create a new public method | + | |
- | called | + | |
- | get name which simply returns | + | |
- | that name property that i just set up | + | |
- | so now if i go to combined | + | |
- | ini i can | + | |
- | add parameters to a recommendation | + | |
- | module by just putting in a colon and | + | |
- | then adding stuff | + | |
- | after the colon so | + | |
- | let's say the tutorial results | + | |
- | put this whole thing in double quotes | + | |
- | since it has spaces in it | + | |
- | we want to be sure the configuration | + | |
- | parses correctly | + | |
- | so at this point | + | |
- | the tutorial results will get passed to | + | |
- | the set config method | + | |
- | then it will get stored in the this name | + | |
- | property and it will be available for | + | |
- | retrieval through this public | + | |
- | get name method | + | |
- | where we want to retrieve it | + | |
- | is in our template which by convention | + | |
- | is going to have access to our | + | |
- | combined notes class using the name this | + | |
- | arrow recommend | + | |
- | this escape | + | |
- | want to be sure that we don' | + | |
- | special characters in our text | + | |
- | this recommend get name | + | |
- | and i will delete | + | |
- | combined | + | |
- | and actually just for completeness | + | |
- | going to go back | + | |
- | and make my set config | + | |
- | smarter | + | |
- | say if the settings are empty | + | |
- | we'll call it combine | + | |
- | otherwise | + | |
- | way | + | |
- | it has a reasonable default but it can | + | |
- | be overwritten | + | |
- | so again the flow i put a parameter | + | |
- | on the recommendation module | + | |
- | configuration in my any file | + | |
- | it passes to set config which stores it | + | |
- | my class exposes the stored property | + | |
- | through a get name property | + | |
- | and i can call that get name property in | + | |
- | my template | + | |
- | uh by referring to the this recommend | + | |
- | object which is always going to be | + | |
- | available in any recommendation module | + | |
- | template | + | |
- | pointing at the instance of the | + | |
- | recommendation module class | + | |
- | so now i come back here and i refresh | + | |
- | the page | + | |
- | combined | + | |
- | the tutorial results | + | |
- | and i've showed you both how to | + | |
- | configure a recommendation module | + | |
- | and how to use properties of the | + | |
- | recommendation module to render a | + | |
- | response | + | |
- | let's do just one more clever thing | + | |
- | and show a count of uh | + | |
- | i'm sorry and so | + | |
- | let's just do one more clever thing and | + | |
- | show the user's | + | |
- | search query uh along with the message | + | |
- | we can do that | + | |
- | by going to the process method | + | |
- | which receives an instance of you finds | + | |
- | search results object after the search | + | |
- | has been completed | + | |
- | well first let's create another property | + | |
- | we'll call this | + | |
- | query | + | |
- | and then in the process we can say | + | |
- | this query equals results | + | |
- | get params | + | |
- | get display query which is how you get | + | |
- | access to the user's | + | |
- | input in a human readable form | + | |
- | from a search results object | + | |
- | we also need to | + | |
- | create a get query method | + | |
- | to expose this property so that the | + | |
- | view template can read it so we just | + | |
- | create a get | + | |
- | query that returns this query | + | |
- | save all of that and now | + | |
- | in our template here | + | |
- | we can add four query colon | + | |
- | single quote and then embed | + | |
- | this escape | + | |
- | recommend get query close friends | + | |
- | and save that | + | |
- | and let me actually do a search that has | + | |
- | a query to make this more interesting | + | |
- | and sure enough now it says you're | + | |
- | looking at the tutorial results for | + | |
- | query web | + | |
- | so again my search query got processed | + | |
- | the recommendation module pulled that | + | |
- | out of the results object | + | |
- | and we displayed it right here of course | + | |
- | there' | + | |
- | lot of depth to what viewfind | + | |
- | but the point here is that you can build | + | |
- | small | + | |
- | plug-ins | + | |
- | other pieces | + | |
- | and you can pull things out and push | + | |
- | them to the display | + | |
- | so that you can do some fairly | + | |
- | sophisticated customizations | + | |
- | from within your local module with | + | |
- | relatively little effort | + | |
- | next time around | + | |
- | more code generators | + | |
- | and show you how to do some other | + | |
- | advanced customizations | + | |
- | until then as always feel free to reach | + | |
- | out with questions | + | |
- | through the mailing lists or slack | + | |
- | and have a good month | + | |
---- struct data ---- | ---- struct data ---- | ||
+ | properties.Page Owner : | ||
---- | ---- | ||
videos/code_generators_1.1602596331.txt.gz · Last modified: 2020/10/13 13:38 by demiankatz