CodeIgniter Forums
Autoload Libraries (from CI3) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Autoload Libraries (from CI3) (/thread-71926.html)



Autoload Libraries (from CI3) - Alex1Strakhov - 10-12-2018

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();
 
   }





RE: Autoload Libraries (from CI3) - InsiteFX - 10-12-2018

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

CodeIgniter 4 Users Guide - Autoloading Files


RE: Autoload Libraries (from CI3) - titounnes - 10-12-2018

(10-12-2018, 01: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);