• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Autoload Libraries (from CI3)

#1
In CI3:

config/autoload.php

PHP Code:
$autoload['libraries'] = array('test_lib'); 

controller/Test.php

PHP Code:
class Test extends CI_Controller
{

 
   public function index()
 
   {
 
       echo $this->CI->test_lib->variable;

 
       $this->CI->test_lib->method();
 
   }




The library was connected automatically, access to it was in any part of the project.


How to make it so that in CI4 was like this:

PHP Code:
class Test extends CI_Controller
{

 
   public function index()
 
   {
 
       echo TestLib->variable;

 
       TestLib->method();
 
   }


Reply

#2
See the CodeIgniter 4 ./application/Config/Autoload.php

CodeIgniter 4 Users Guide - Autoloading Files
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
(10-12-2018, 02:46 AM)Alex1Strakhov Wrote: In CI3:

config/autoload.php

PHP Code:
$autoload['libraries'] = array('test_lib'); 

controller/Test.php

PHP Code:
class Test extends CI_Controller
{

 
   public function index()
 
   {
 
       echo $this->CI->test_lib->variable;

 
       $this->CI->test_lib->method();
 
   }




The library was connected automatically, access to it was in any part of the project.


How to make it so that in CI4 was like this:

PHP Code:
class Test extends CI_Controller
{

 
   public function index()
 
   {
 
       echo TestLib->variable;

 
       TestLib->method();
 
   }


in CI4, more simple.
$myLib = (new \App\Libraries\MyLib)->method();
print_r($myLib);
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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