It wasn’t advertised or was made known, but since the release of 6.2.7, you have the ability to do even greater customizations of the system without worrying about updates destroying your work. This is an alternative solution to doing custom fields. Here are a list of routers you can override:
- Dashboard – app/routers/dashboard.router.php
- Application – app/routers/appl.router.php
- Course – app/routers/course.router.php
- Name and Address – app/routers/person.router.php
- Program – app/routers/person.router.php
- Course Section – app/routers/section.router.php
- Student – app/routers/student.router.php
When we talk about overriding a router, we don’t mean routes such as /nae/, /sect/, etc. What’s meant is that you get to override the specific router file by requiring a different one. In order to do so, follow the steps below. We will use person.router.php as an example.
Step 1: Create a new custom router directory (app/custom-routers/).
Step 2: Create a new custom views directory in the views directory (app/views/custom-views/).
Step 3: Since we are working with the person router, create a person folder in your new custom views folder (app/views/custom-views/person/).
Step 4: Copy view files from app/views/person/* and paste them into app/views/custom-views/person/. You only need to copy over the view files you are wanting to customize.
Step 5: Now you can customize the custom person router with database customizations and also the custom view with custom fields or whatever.
Step 6: If you have a customized view for a specific route, then you need to let your customized person router know where that view/display is located. So if you are doing a custom view for the following route /nae/12/ (viewing a particular person record), then you will need to change this:
$app->view->display('person/view', [ 'title' => get_name($decode['personID']), 'cssArray' => $css, 'jsArray' => $js, 'nae' => $decode, 'addr' => $q, 'staff' => $staff, 'appl' => $appl ]);
$app->view->display('custom-views/person/view', [ 'title' => get_name($decode['personID']), 'cssArray' => $css, 'jsArray' => $js, 'nae' => $decode, 'addr' => $q, 'staff' => $staff, 'appl' => $appl ]);
Step 7: You will then need to download, customize, upload, and activate the Custom Routers plugin. The example code in the plugin follows the example in this article. The code in the plugin basically hooks into a filter allowing you to override the native router with your customized one.