Always start a particular service... |
(09-29-2017, 07:40 AM)Tripex Wrote: Is there a way to always start up a service without having to do it through your controller? (similar to the helpers variable but global). 1) Define "service". 2) Have you actually read the user guide (documentation)? 3) What the heck is a "helpers variable"? 4) It's pretty hard to do straightforward stuff when you can't describe what you're doing. 5) Stay in the box. If you don't know what you're doing and you venture outside the box, you'll be roaming in dangerous territory.
The controller is making your life easier with web services! Why dont you explore further and advance your skill with CI? I build my api from CI controllers
Good luck (09-29-2017, 04:49 PM)skunkbad Wrote:(09-29-2017, 07:40 AM)Tripex Wrote: Is there a way to always start up a service without having to do it through your controller? (similar to the helpers variable but global). As for 1), 2) and 3)... We are in the context of CI 4 and I assumed that when I say "service" that we are talking about CI services. The current intended way to start those seems to be in your controller by calling the corresponding service from Services.php E.g. PHP Code: $session = \Config\Services::session($config); In the system/Controller.php file there is a $helpers variable (class member) that takes an array of helpers you want to load with your controller... automatically. My question was if there was a way to start up your services automatically so that it is available in all your controllers without having to type it in for every controller... OR if there was an equivalent class member of Controller that could be used for services to at least have some consistency in how these things are started. I know I can inherit the class and do it myself but I really think this should be part of the framework. I hope that makes it clearer....... As for 4) and 5) I know that you sometimes on forums like these can get a lot of newcomers that don't know what they are talking about or don't make sense... and I understand that it can be frustrating but these kind of comments from regulars (like you) here on the forums are NOT helping new people like me to get into the project. I have both read the documentation and the source code and I'm getting familiar with the ins and outs of this project because I want to contribute. You really should think about how you approach people. I falsely assumed that it was understood what a "Service" was in the context of CI, I also assumed that it was known there was a $helpers class member (perhaps worded wrongly by saying "variable", but never mind) because it is in the documentation; it seems that this assumption was wrong and therefore it seemed like my question was incoherent, BUT it is offensive to practically be label incompetent by telling them to "Stay in the box". I would hope that you think about being more open to other new comers as to encourage people to contribute.
Currently there is not a way to automatically load Services. Helpers are fairly simple to do since they don't have to be assigned to any specific variable within the class, but not so with Services. The way this was discussed internally, is that most of the time it would happen through a base controller that your other controllers extend from, or, if you needed it within many functions of the controller, you would grab an instance during __construct and assign it to a class property. This seemed like the best option, based on code we'd all seen where everything gets autoloaded for every controller in the application whether it's needed or not. That, and we didn't want to auto-assign class property names based on the service name since it may conflict with other stuff you're doing.
(10-02-2017, 06:27 AM)kilishan Wrote: Currently there is not a way to automatically load Services. Helpers are fairly simple to do since they don't have to be assigned to any specific variable within the class, but not so with Services. The way this was discussed internally, is that most of the time it would happen through a base controller that your other controllers extend from, or, if you needed it within many functions of the controller, you would grab an instance during __construct and assign it to a class property. This seemed like the best option, based on code we'd all seen where everything gets autoloaded for every controller in the application whether it's needed or not. That, and we didn't want to auto-assign class property names based on the service name since it may conflict with other stuff you're doing. Thank you, this makes sense. I'll just make my own base controller and inherit from that. |
Welcome Guest, Not a member yet? Register Sign In |