Home » Php » php – How to include class in symfony 5?

php – How to include class in symfony 5?

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have a php file with Paysafecard class. File is called Paysafecard.php. I’d like to include it in my controller. How can I do it?

How to&Answers:

If you are using symfony surely you are using the composer autoload.

Go to the root directory path of your project and search the composer.json file.

Within it you find a directive like this :

 "autoload": {
        "psr-4": {
            "App\": "src/"
        }
    },

This sentence indicates the mapping between the name and the directory.

Now look at the actual file path, for example /src/lib/Paymenterio.php

Go to the controller where you want to use the class replace the path with the autoload alias and remove the extension.

use App\lib\Paymenterio;