• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What are the CI4 ways to use Database and Library in a Helper?

#6
(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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.