Welcome Guest, Not a member yet? Register   Sign In
Call file / class from ThirdParty folder
#3

(This post was last modified: 11-25-2019, 04:17 PM by StefenKhoe.)

(11-22-2019, 07:56 AM)MGatner Wrote: That's the correct way to call it, so you probably don't have it loaded. Read up on autoloading if you'd like the framework to handle it for you:
https://codeigniter4.github.io/userguide...oader.html

For example, if you wanted to use your code above, app/Config/Autoload.php might look like this:


PHP Code:
$psr4 = [
    
'Config'      => APPPATH 'Config',
    
APP_NAMESPACE => APPPATH,                // For custom namespace
    
'App'         => APPPATH,                // To ensure filters, etc still found,
    
'TP\Tools'    => APPPATH 'ThirdParty/TpTools',
]; 

(You might want to use the classmap instead, depending on what the library looks like.)

Hi MGatner,

sorry for my late reply, thankyou so much for your help,
i try your solution but still not work yet,
and i try using classmap too.. but not work too..

updating my autoload.php 
PHP Code:
        $psr4 = [
            
'Config'      => APPPATH 'Config',
            
APP_NAMESPACE => APPPATH,                // For custom namespace
            
'App'         => APPPATH,               // To ensure filters, etc still found,
            
'TP\Tools' => APPPATH 'ThirdParty/Foo.php'
        
]; 


Foo.php ( locate at ThirdParty folder) look like this 
PHP Code:
<?php namespace TP\Tools;

/**
 * 
 */
class Foo
{
    public static function 
check1(){
        echo 
"string";
    }
}

?>

User controller
PHP Code:
<?php namespace App\Controllers;

use 
CodeIgniter\Controller;
use 
App\Models\UserModel;
use 
TP\Tools;

class 
User extends BaseController
{
    private 
$usermodel;

    public function 
__construct()
    {
        $this->usermodel = new UserModel();
    }

    public function index(){
        Foo::check1();
    } 
Reply


Messages In This Thread
RE: Call file / class from ThirdParty folder - by StefenKhoe - 11-25-2019, 06:17 AM



Theme © iAndrew 2016 - Forum software by © MyBB