A controller is always attached to a template.
I needed to have the same code in three different controllers. I felt bad about duplicating the code. It also felt strange to create a plugin and jump between the controller and the plugin.
In the controllers where you have duplicated code, (for example
/site/controllers/home.php) do this:
require_once kirby()->roots()->controllers() . '/shared/my-shared-controller.php';
Try it out
<?php echo 'Shared controller'; die;
If it work, it will print “Shared controller” on the screen and nothing more.