CodeIgniter Forums
CI 4 - beginner problems - Printable Version

+- CodeIgniter Forums (
+-- Forum: Using CodeIgniter (
+--- Forum: General Help (
+--- Thread: CI 4 - beginner problems (/showthread.php?tid=76607)

CI 4 - beginner problems - boddah85 - 06-01-2020


Im trying to make a switch from CI3 to CI4. I must admit that I really like ci3, however ci4 looks great and I'm looking forward to make an apps with new version o ci.

At the beginning, for the testing purspose, I'm trying to write a really simple auth libarary. In CI3 i would create MyAuth in application/library:
PHP Code:
class MyAuth

public function 
$this->firstName.' '.$this->lastName;

in controller i could load it
PHP Code:
public function testing

and in view I could print it like that:
PHP Code:
echo $this->myauth->getName(); 

Is there any way to do the same in ci 4?

Sorry but I can't find many informations about creating libraries in CI 4.

Second question:
How to check if there's database connection?
In CI 3 i checked it this way:
PHP Code:
$connDB $this->load->database('default',TRUE);
//redirect to static page

In ci 4 when im'trying
PHP Code:
$this->dbSocket = \Config\Database::connect($custom); 

dbSocket->connID is always false.

RE: CI 4 - beginner problems - fujael - 06-01-2020

I guess you're kind of stuck with `load` object to initiate a library. This new CI4 is way better in my opinion to load library. You can load your library class by this

> Create a class under `app/Libraries`
> Make sure you are using namespace like this

PHP Code:
namespace App\Libraries
> Go to controller and load it by calling directly
PHP Code:
$this->libraryName = new App\Libraries\{ClassName}; 
That's it.

{The opinion is my own, this is not official}