MVC — how to get rid of duplicate code in the controller?

There is a function from a javascript autocomplete.
To get rid of the duplication of this function in a different View, I can write it in a separate static class in php function (echo). And then in the right View to display a php function that will write my JS function.
This is with regard to View. And what about the controller? autocomplete is AJAX. There is a script for php. How to get rid of duplicating it in different controllers?
I can't send the data to a simple class (not controller) to the url in AJAX. Because that url does not exist (the class after all, not the controller). I can't go to another controller, because its instance is not created (I have open View to the current controller).
June 10th 19 at 15:54
1 answer
June 10th 19 at 15:56
trait or method in the parent controller

Find more questions by tags PHPMVC