Warning: This page has not been updated in over over a year and may be outdated or deprecated.
development:plugins:controllers
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
development:plugins:controllers [2020/03/03 20:20] – [Overriding an Existing Controller] demiankatz | development:plugins:controllers [2021/08/03 14:04] (current) – demiankatz | ||
---|---|---|---|
Line 31: | Line 31: | ||
* Create a [[development: | * Create a [[development: | ||
- | * Create a new class in your module' | + | * Create a new class in your module' |
- | * In your module' | + | * If you used the code generator, you are now done. If you are setting things up manually, you will also need to add some configuration to activate your new class. |
< | < | ||
Line 38: | Line 38: | ||
' | ' | ||
' | ' | ||
- | ' | + | ' |
+ | ], | ||
+ | ' | ||
+ | ' | ||
], | ], | ||
], | ], | ||
Line 48: | Line 51: | ||
Creating a new controller is much like overriding an existing one. | Creating a new controller is much like overriding an existing one. | ||
- | * As described above, create a custom module, build a new controller, and set up an invokables | + | * As described above, create a custom module, build a new controller, and set up a factory |
- | * Now you need to add routing rules so the framework knows how to find your controller and so you can conveniently link to it within templates. | + | * Now you need to add routing rules so the framework knows how to find your controller and so you can conveniently link to it within templates. |
==== Example - How to add a new page to your theme ==== | ==== Example - How to add a new page to your theme ==== | ||
- | // Note: this example | + | :!: This example |
- | | + | // Note: this example assumes you have set up a [[development: |
- | It extends AbstractBase and contains just a function | + | |
+ | | ||
+ | |||
+ | php $VUFIND_HOME/public/ | ||
+ | |||
+ | * This command will create a file called $VUFIND_HOME/module/MyModule/src/MyModule/Controller/ | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | |||
+ | namespace MyModule\Controller; | ||
+ | |||
+ | class TestController extends \VuFind\Controller\AbstractBase | ||
+ | { | ||
+ | /** | ||
+ | * | ||
+ | * @return \Laminas\View\Model\ViewModel | ||
+ | */ | ||
+ | public function homeAction() | ||
+ | { | ||
+ | return $this-> | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | * Now set up a static route to this new controller action like this: | ||
+ | |||
+ | php $VUFIND_HOME/ | ||
+ | |||
+ | * Then create in your theme a directory and a file (lowercase) named as in the configuration | ||
+ | * Put your contents in that file. For example, you can try this: | ||
+ | |||
+ | <code php> | ||
+ | This is my test page -- it embeds behavior from the search page: | ||
+ | <? | ||
+ | </ | ||
- | class TestController extends AbstractBase | + | |
- | { | + | |
- | /** | + | |
- | * | + | |
- | * @return \Laminas\View\Model\ViewModel | + | |
- | */ | + | |
- | public function homeAction() | + | |
- | { | + | |
- | return $this->createViewModel(); | + | |
- | } | + | |
- | } | + | |
- | * In / | + | ===== Related Video ===== |
- | below the ' | + | |
- | add a new | + | |
- | ' | + | |
- | ' | + | |
- | and below | + | |
- | $staticRoutes | + | |
- | add your template filename and path | + | |
- | ' | + | |
- | * Then create in your theme a directory and a file (lowercase) named as in the configuration (e.g. / | + | See the [[videos: |
- | * Put your contents in that file. For test you can try with | + | |
- | ''< | + | |
---- struct data ---- | ---- struct data ---- | ||
+ | properties.Page Owner : | ||
---- | ---- | ||
development/plugins/controllers.1583266803.txt.gz · Last modified: 2020/03/03 20:20 by demiankatz