Can't load a Non

It's the first time that I try to load a Composer package that doesn't use a Laravel service provider or a facade.

I am trying to install this package: https://github.com/mollie/mollie-api-php

I have followed the steps to install the package with Composer.

At the top of my controller I added:

require_once base_path('vendor/Mollie/API/Client.php');

I get the following error:

main(): Failed opening required '../vendor/Mollie/API/Client.php' (include_path='.:/Applications/MAMP/bin/php/php7.0.0/lib/php')

It can't find the file. Even though the path in the error is the path where the class is located. Are there more steps I should do?

Structure of the package:

在这里输入图像描述

composer.json from the package:

"autoload": {
    "psr-0": {
        "": "src/"
    }

Update: My controller has this namespace

namespace AppHttpControllers;

So when i just try to new up my class it obviously can't find that class inside that namespace. So how do i ignore the namespace for 1 class

Because this will not work inside this controller:

$mollie = new Mollie_API_Client;

As noted in the comments, Composer handles the autoloading for you - manually re-requiring it isn't necessary and may in fact cause problems.

my controller has a namespace, so it tries to load that class from the namespace, how do i ignore it for 1 class?

You can reference the class with a leading , ie new Mollie_API_Client , which will tell PHP to look in the root instead of your controller's namespace.

You can also put use Mollie_API_Client; at the top of the file to accomplish a similar thing. You'll see use statements at the top of a lot of Laravel files for this reason.

链接地址: http://www.djcxy.com/p/88648.html

上一篇: 在Laravel 5中使用HybridAuth错误无法声明类Hybrid

下一篇: 无法加载Non