CodeIgniter Forums
Autoload Library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Autoload Library (/showthread.php?tid=69372)



Autoload Library - Vykintas - 11-10-2017

Hi,

I try run autoload Library

In autoload file /Config/Autoload.php I use this

$classmap = [
     'User' => APPPATH . 'libraries/user.php'
];

and I want auto run this class like CI3 $this->load->library('User');

In CI3 this class run automatically constructor, how to do this in CI4?

I new in CI4


RE: Autoload Library - Narf - 11-11-2017

(11-10-2017, 01:19 PM)Vykintas Wrote: Hi,

I try run autoload Library

In autoload file /Config/Autoload.php I use this

$classmap = [
     'User' => APPPATH . 'libraries/user.php'
];

and I want auto run this class like CI3 $this->load->library('User');

In CI3 this class run automatically constructor, how to do this in CI4?

I new in CI4

You new in PHP. I suggest that you learn a bit more about classes and objects first, after which you wouldn't be asking this question.


RE: Autoload Library - donpwinston - 11-11-2017

put User.php in the Libraries folder and invoke it with $user = new \App\Libraries\User(); Have to learn namespaces for CI4.


RE: Autoload Library - Vykintas - 11-13-2017

Ok, I'll ask you more simply

on CI3 automatically load library I just add this in autoload.php

$this->load->library('User');

and in controller i can call User library methods like $this->user->getId();


How do This on CI4?


RE: Autoload Library - donpwinston - 11-13-2017

There is no $this->load->library(). CI4 doesn't work this way anymore. There's an Autoload.php config file but it works differently. It uses class mapping and name spaces. It's much less dorky(more modern) than calling $this->load->library().


RE: Autoload Library - jaynarayan - 11-14-2017

I hope this would help 
https://bcit-ci.github.io/CodeIgniter4/concepts/autoloader.html