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

(08-15-2019, 10:34 AM)dave friend Wrote:
(08-15-2019, 10:21 AM)webdevron Wrote: I need to use a database model and library in my helper. Also need to use a library. In CI 3 I used to do it like following:

PHP Code:
$CI =& get_instance();
$CI->load->model('a_modal');
$CI->load->library('a_library'); 

Now I am little bit confused about the CI 4. What are the ways to do this? What is the CodeIgniter way to do it?

Thanks in advance.

I answered you here, where you previously asked this question.

Thanks for your response in both threads. It was 15 minutes before my post. Currently I'm solving the issue like bellow.

PHP Code:
// -------------------------- BaseController Constructor
public function initController(......){
 
   $this->_db = \Config\Database::connect();
 
   $this->_model = new \App\Models\a_model();
}
// -------------------------- Function in BaseController
public function some_function( ){
 
   a_helper_function$this ); // Here '$this' is the BaseController Instance


Need your feedback about this solutions.
Again I am little bit confused about Service. I have read through the docs but still not clear about understanding "What is service?".
"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, 11:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB