About Features Downloads Getting Started Documentation Events Support GitHub

Love VuFind®? Consider becoming a financial supporter. Your support helps build a better VuFind®!

Site Tools


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.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
development:plugins:controllers [2020/05/12 12:16] – [Creating a New Controller] demiankatzdevelopment:plugins:controllers [2020/05/12 12:27] demiankatz
Line 56: Line 56:
 ==== Example - How to add a new page to your theme ==== ==== Example - How to add a new page to your theme ====
  
-:!: This example is out of date; it will be updated soon to reflect VuFind 7.0 standards.+:!: 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 shows how to modify the VuFind core; localizing changes to separate module requires some additional work. //+// Note: this example assumes you have set up [[development:architecture:customizing_vufind#modules|local custom module]] called MyModule and a [[development:architecture:user_interface#creating_a_theme|local custom theme]] called mytheme. //
  
-  * Create a new controller in /vufindroot/module/VuFind/src/VuFind/Controller and name it as you want (e.g. TestController.php)+  * Create a new controller called TestController, using this command (which sets up the controller to be built using VuFind's standard controller factory):
-It extends AbstractBase and contains just a function that returns an array:+
  
- class TestController extends AbstractBase +  php $VUFIND_HOME/public/index.php generate plugin MyModule\\Controller\\TestController VuFind\\Controller\\AbstractBaseFactory
-+
- /** +
-+
- * @return \Laminas\View\Model\ViewModel +
- */ +
- public function homeAction() +
-+
- return $this->createViewModel(); +
-+
- }+
  
-  * In /vufind2root/module/VuFind/config/module.config.php   +  * This command will create a file called $VUFIND_HOME/module/MyModule/src/MyModule/Controller/TestController.phpEdit it, and add a homeAction method so that it looks like this:
-below the 'controllers' => array( +
-add a new  +
-      'invokables' => array( +
-        'test'  => 'VuFind\Controller\TestController', +
-and below +
-$staticRoutes = array( +
-add your template filename and path +
-  'Test/Home',+
  
-  * Then create in your theme a directory and a file (lowercase) named as in the configuration (e.g. /vufindroot/themes/demovufind/templates/test/home.phtml) +<code php> 
-  * Put your contents in that file. For test you can try with  +<?php 
-''<nowiki><?=$this->render('search/home.phtml');?></nowiki>''+ 
 +namespace MyModule\Controller; 
 + 
 +class TestController extends \VuFind\Controller\AbstractBase 
 +
 +    /** 
 +     * 
 +     * @return \Laminas\View\Model\ViewModel 
 +     */ 
 +    public function homeAction() 
 +    { 
 +        return $this->createViewModel(); 
 +    } 
 +
 +</code> 
 + 
 +  * Now set up a static route to this new controller action like this: 
 + 
 +  php $VUFIND_HOME/public/index.php generate staticroute Test/Home MyModule  
 + 
 +  * Then create in your theme a directory and a file (lowercase) named as in the configuration (e.g. $VUFIND_HOME/themes/mytheme/templates/test/home.phtml) 
 +  * Put your contents in that file. For example, you can try this: 
 + 
 +<code php> 
 +This is my test page -- it includes a copy of the home page: 
 +<?=$this->render('search/home.phtml');?> 
 +</code>
 ---- struct data ---- ---- struct data ----
 ---- ----
  
development/plugins/controllers.txt · Last modified: 2021/08/03 14:04 by demiankatz