'CI4 - Want to use Controller function inside another Controller
I want to create a LogController and Access it directly on other controller. I don't want to use Extends LogController as it is already extending something. If there is a way to use functions of LogController in Another Controller?
Solution 1:[1]
May want to rethink your approach. You should not be calling one controller from another, it's bad design.
You should have some sort of business class that handles the logging, which your controllers can call. If possible, I would use Dependency Injection to pass this to each of the controllers
The LogController, I would only have to allow for the UI to access logging via API endpoints (if you want to log js errors), or for the purpose of displaying log entries. But again, I would still have a business class of some sort that actually does the logging (and/or reads the lo.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Carl J |