• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Autoload Library

#1
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
Reply

#2
(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.
Reply

#3
put User.php in the Libraries folder and invoke it with $user = new \App\Libraries\User(); Have to learn namespaces for CI4.
Simpler is always better
Reply

#4
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?
Reply

#5
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().
Simpler is always better
Reply

#6
I hope this would help 
https://bcit-ci.github.io/CodeIgniter4/c...oader.html
          Heart  love codeigniter Heart
          Learning  best  practices
     Rate my post if you found it helpfull
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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