Valkyrurr
Valkyrurr

Reputation: 119

How to implement php packages

Ok so I have been learning vanilla php and wanted to delve into making use of packages. so I tried implementing fabpot\Goutte to the teeth.

I did install the package using Composer and placed the src code in the root folder where the Composer-generated files sit. As I run the script, I get an initializing class not found error.

How do I get around with this? I have followed the instructions and it's making me crazyyyyyyyyyyyy

Code I got:

<?php

use Goutte\Client;

// Initialize object
$client = new Client();

// Issue GET request to URI
$crawler = $client->request("GET", "http://www.symfony.com/blog");
$client->getClient()->setDefaultOption("config/curl".CURLOPT_TIMEOUT, 60);

// Navigate the client through the use of links
$link = $crawler->selectLink("Security Advisories")->link();
$crawler = $client->click($link);


// Extract data
$crawler->filter("h2 > a")->each(function($node) {

    print $node->text()."\n";

});

?>  

The error I am getting:

Fatal error: Class 'Goutte\Client' not found in **line 6**  

Upvotes: 2

Views: 2397

Answers (1)

Rahul M
Rahul M

Reputation: 1509

On top of your script.. You need to include composer's autoloader like this:

require __DIR__ . "/vendor/autoload.php";

Upvotes: 16

Related Questions