CodeIgniter Forums

Full Version: Autoload Library
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
(11-10-2017, 02: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.
put User.php in the Libraries folder and invoke it with $user = new \App\Libraries\User(); Have to learn namespaces for CI4.
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?
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().