Welcome Guest, Not a member yet? Register   Sign In
How to create a library?
#4

(This post was last modified: 12-08-2019, 06:40 AM by MatheusCastro.)

(12-07-2019, 09:24 PM)ciadmin Wrote: Er, The above advice is more for CI3.

For CI4, create libraries as classes inside some app folder, eg app/Libraries, and make sure that they are properly namepaced.

Eg:
<?php namespace App\Libraries\MyStuff;
class MyStuff {
}


and then load/reference it with
$mystuff = new App\Libraries\MyStuff();

and away you go.

Perfect, it works! Exemple: 

PHP Code:
<?php

namespace App\Libraries\Payment;

class 
Payment
{

    public function configName($name): string
    
{
        return $name;
    }


Another thing, it is recommended to use

PHP Code:
new \App\Libraries\Payment(); 

Or: 

PHP Code:
//This
use  App\Libraries\Payment;

class 
Home extends Controller
{
    public function index()
    {
        //This
        $payment = new Payment();

    {... } 
Reply


Messages In This Thread
How to create a library? - by MatheusCastro - 12-07-2019, 11:29 AM
RE: How to create a library? - by acewebcreations - 12-07-2019, 08:51 PM
RE: How to create a library? - by ciadmin - 12-07-2019, 09:24 PM
RE: How to create a library? - by MatheusCastro - 12-08-2019, 04:27 AM
RE: How to create a library? - by Martin_Salas - 12-15-2019, 06:40 AM
RE: How to create a library? - by InsiteFX - 12-15-2019, 09:33 AM
RE: How to create a library? - by Martin_Salas - 12-15-2019, 03:12 PM
RE: How to create a library? - by miqueiaspenha - 07-02-2020, 12:26 PM
RE: How to create a library? - by cvlancvlan - 06-30-2020, 09:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB