Controller Constructor Parameter init |
Hi,
I would like to know if it is possible to init the controller with route parameter issued to each method within the controller? Sorry if this is stated in the documentation, I have read through it quite throughly and haven't come across a specific answer to this but could i possibly instantiate a controller class with a routing parameter set class wide, such as... Code: __constructor(private int $event_id) {} rather than having to set... in each method... Code: $this->event_id = $event_id; Is this possible or not? Thanks in advance
The framework does not support named route parameters and autowiring. So it's not possible in the current implementation.
Probably it would be possible if you do the following two things:
1. Extend Router to implement named route parameters 2. Extend CodeIgniter class to inject the named parameters when creating a controller
Looks like they may be moving towards implementing this feature from the looks of the more recent Uri Routing documentation
https://codeigniter.com/user_guide/incom...ble-syntax PHP Code: use App\Controllers\Product; Thanks any way for your prompt replies. If i do find time to help out with this feature i will surely help out any way i can. Don't think it is an issue which causes mny pains but think it might be nice for future iterations, helping to clean up controller classes. |
Welcome Guest, Not a member yet? Register Sign In |