Accessing PHP library in CI4 |
Hello,
I am rewriting my old CI3 project to CI4. I have a part where the app accesses the external PHP library and uses its functions. it looks like this: PHP Code: require_once('libwebtopay/WebToPay.php'); But in CI4, I get an error. Class 'App\Controllers\WebToPay' not found It looks like CI4 thinks that WebToPay is a controller. Is it possible to make CI4 read external PHP classes?
Thank you, it worked!
Now looks like it gets to the library. I don't know if this error is familiar with the previous one. Any idea of how to solve it?
this looks like its about namespaces by the way i came across a nifty check using spark
cd to root of app and run from command line: Code: php spark namespaces thats tells you what namespaces can be found. on the Code: require_once('libwebtopay/WebToPay.php'); CI4 uses as far as i can see 2 ways to find classes, if you use composer to get software it automatically loads if not you add entries to app/Config/Autoload.php Now i use PHPmailer and had a similar problem. First i told CI4 where to find classes via $psr4 in Autoload, then there are several classes so i listed them all in the controller: use PHPMailer\PHPMailer\OAuth; use PHPMailer\PHPMailer\Exception; use .. you see that Exception class for PHPMailer, i think you have an exception class in your webpay which it needs to have access to: Do you have a link to the webpay so i can have a look ? Also always interested in 3rd party stuff i might be able to use!
Thank you for your answer! It really helped me a lot.
This is how I solved my problem: I just added those classes into Autoload $classmap: it looks like this now: PHP Code: public $classmap = [ Let me know if it's ok to use it this way. But at least it works fine now.
I see the WebToPay lib is not using namespaces. In that case, your classmap approach is preferred.q
|
Welcome Guest, Not a member yet? Register Sign In |