Welcome Guest, Not a member yet? Register   Sign In
What are the CI4 ways to use Database and Library in a Helper?
#6

(This post was last modified: 08-15-2019, 12:28 PM by webdevron.)

(08-15-2019, 12:05 PM)kilishan Wrote: A "Service" is just a function that takes care of initializing an object with any dependencies it needs, and returning it. By default it returns the same instance every time that it's called so it's shared across the application, but you can request a new instance easily.

As for your code example - I wouldn't pass a controller into a helper function. Just pass what it needs, which is likely just the model at that point, since the model contains it's own pointer to the database.

PHP Code:
// -------------------------- Function in BaseController
public function some_function( ){
 
   a_helper_function$this->_model ); // Here '$this' is the BaseController Instance


Thank you kilishan. I just need to know that, My process is not bad and you make me feel that.
"Who thinks in code"
Perfectly describes who I am
mbparvez.me
Reply


Messages In This Thread
RE: What are the CI4 ways to use Database and Library in a Helper? - by webdevron - 08-15-2019, 12:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB