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

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

Reply


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



Theme © iAndrew 2016 - Forum software by © MyBB