![]() |
Call file / class from ThirdParty folder - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Call file / class from ThirdParty folder (/showthread.php?tid=74893) |
Call file / class from ThirdParty folder - StefenKhoe - 11-21-2019 Hello, guys i have the problem to load file class that i place it at ThirdParty folder, i try using namescape, require, require_once, include and etc.. but nothing work example i have this Foo.class PHP Code: <?php namespace TP\Tools; Try to call in PHP Code: <?php namespace App\Controllers; is it wrong ? pls advise better way to load another file because i cant find it anywhere at user guide.. Thankyou guys for your help RE: Call file / class from ThirdParty folder - MGatner - 11-22-2019 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/concepts/autoloader.html For example, if you wanted to use your code above, app/Config/Autoload.php might look like this: PHP Code: $psr4 = [ (You might want to use the classmap instead, depending on what the library looks like.) RE: Call file / class from ThirdParty folder - StefenKhoe - 11-25-2019 (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: 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 = [ Foo.php ( locate at ThirdParty folder) look like this PHP Code: <?php namespace TP\Tools; User controller PHP Code: <?php namespace App\Controllers; RE: Call file / class from ThirdParty folder - dave friend - 11-25-2019 (11-25-2019, 06:17 AM)StefenKhoe Wrote: The part shown above is not correct. The value should be a path to a folder - NOT to a file. While trying to reproduce your problem here is what worked for me. Both /app/ThirdParty/Foo.php and app/Controllers/User.php remain as you show in the OP. In fact, the only change is to what @MGatner did in /app/Config/Autoload.php. Here what I tried and it works. PHP Code: $psr4 = [ RE: Call file / class from ThirdParty folder - StefenKhoe - 11-29-2019 (11-25-2019, 09:43 AM)dave friend Wrote:(11-25-2019, 06:17 AM)StefenKhoe Wrote: @Dave : super thankyou !, work for me too.. |