Welcome Guest, Not a member yet? Register   Sign In
how i can create my library in codeigniter 4
#3

(04-02-2020, 01:03 PM)Hoodini Wrote: this is easy in codeigniter 3 but i cant find this in codeigniter 4 document

It is even easier than V3. The only tricky bit is learning to use namespace.

Here's a very simple library

app/Libraries/MyCustomClass.php

PHP Code:
<?php namespace App\Libraries;

class 
MyCustomClass
{
 public function 
sayHi()
 {
 return 
"Hello World!";
 }



Here's a simple example of using the custom library in a controller.

PHP Code:
<?php namespace App\Controllers;

use 
App\Libraries\MyCustomClass;  //so we can easily load the custom library

class Home extends BaseController
{
 public function 
index()
 {
 
$mine = new MyCustomClass(); // loads and creates instance
 
echo $mine->sayHi();
 }

Reply


Messages In This Thread
RE: how i can create my library in codeigniter 4 - by dave friend - 04-02-2020, 02:30 PM



Theme © iAndrew 2016 - Forum software by © MyBB