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 | ||
vufind2:building_a_controller [2014/06/13 13:14] – external edit 127.0.0.1 | development:plugins:controllers [2021/08/03 14:04] (current) – demiankatz | ||
---|---|---|---|
Line 5: | Line 5: | ||
===== Background ===== | ===== Background ===== | ||
- | A full description of Zend Framework 2 controllers is beyond the scope of this page, but in a nutshell: | + | A full description of Laminas |
**Controller workflow:** | **Controller workflow:** | ||
Line 17: | Line 17: | ||
* Each action method in a controller needs to return either data to pass to a view or a response object if a non-standard action (like a redirect) is necessary. | * Each action method in a controller needs to return either data to pass to a view or a response object if a non-standard action (like a redirect) is necessary. | ||
- | Some of the resources on the [[Zend Framework 2.0]] page provide more detailed documentation. | + | Some of the resources on the [[development: |
===== VuFind-Specific Controller Conventions ===== | ===== VuFind-Specific Controller Conventions ===== | ||
Line 30: | Line 30: | ||
To override an existing controller, follow these steps: | To override an existing controller, follow these steps: | ||
- | * Create a [[customizing_vufind_2.0# | + | * 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. |
< | < | ||
- | $config = array( | + | $config = [ |
- | ' | + | ' |
- | 'invokables' => array( | + | 'factories' => [ |
- | 'controllername' => ' | + | 'YourNamespace\Controller\ControllerNameController' |
- | | + | ], |
- | | + | ' |
- | ); | + | ' |
+ | | ||
+ | | ||
+ | ]; | ||
</ | </ | ||
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 ==== | ||
+ | |||
+ | :!: This example requires VuFind 7.0 or newer; earlier releases of VuFind required more of this work to be done manually as described above. | ||
+ | |||
+ | // Note: this example assumes you have set up a [[development: | ||
+ | |||
+ | * Create a new controller called TestController, | ||
+ | |||
+ | php $VUFIND_HOME/ | ||
+ | |||
+ | * This command will create a file called $VUFIND_HOME/ | ||
+ | |||
+ | <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 (e.g. $VUFIND_HOME/ | ||
+ | * 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: | ||
+ | <? | ||
+ | </ | ||
+ | |||
+ | * Now point your browser at < | ||
+ | |||
+ | ===== Related Video ===== | ||
+ | |||
+ | See the [[videos: | ||
---- struct data ---- | ---- struct data ---- | ||
+ | properties.Page Owner : | ||
---- | ---- | ||
development/plugins/controllers.txt · Last modified: 2021/08/03 14:04 by demiankatz