Error including Composer (Class not found)

Asked

Viewed 248 times

2

I’m getting the following error:

Fatal error: Class 'wkhtmltopdf Pdf' not found in /Applications/XAMPP/xamppfiles/htdocs/common/class/Prepagoconsulta.php on line 480

Excerpt from the code:

use wkhtmltopdf\Pdf;

class PrePagoConsulta extends Query
{
    public function gerarPDF($html, $nomeArquivo){

        $pdf = new Pdf($html); // * Linha 480

        if (!$pdf->saveAs($_SERVER['DOCUMENT_ROOT'].'/upload/consultas-pre/'.$nomeArquivo.'.pdf')) {
            echo $pdf->getError();
        }
    }
}

And the folder structure is as follows:

Estrutura de classes

In the autoload_psr4.php, I’m setting it this way:

return array(
    'wkhtmltopdf\\' => array($vendorDir.'/wkhtmltopdf/src')
);

How can I correct the error? Where am I missing? hehe

1 answer

2

This scheme is strange, because when it installs it stays in the folder vendor, unless you have set up lib, it seems to me that you did not use Composer to install the packages, but tried to install them manually.

If the package you are using is the https://github.com/mikehaertl/phpwkhtmltopdf, then you installed something wrong, because the package name is not wkhtmltopdf, but yes phpwkhtmltopdf (prefixed "php"), so the right thing should be:

use mikehaertl\wkhtmlto\Pdf;

class PrePagoConsulta extends Query
{
    public function gerarPDF($html, $nomeArquivo){

        $pdf = new Pdf($html); // * Linha 480

        if (!$pdf->saveAs($_SERVER['DOCUMENT_ROOT'].'/upload/consultas-pre/'.$nomeArquivo.'.pdf')) {
            echo $pdf->getError();
        }
    }
}

However if you installed it manually I really recommend that you review it and try to install it via command line (which is exactly what Composer does), do something like:

cd pastadomeuprojeto
composer require mikehaertl/phpwkhtmltopdf

Ready it will do everything manually, so import:

use mikehaertl\wkhtmlto\Pdf;
  • @Guilhermenascimento was installed by hand. I haven’t found Composer yet. I would like these libs to be installed inside the /common/libs folder... I tried to do the installation, but it’s always a problem... see: https://i.imgur.com/8Vreuyw.png

  • @Guilhermenascimento tried using php in front of the Composer, and without also.

  • I can’t install this dependency manually then? Well... I’ll give it a read then.

  • 1

    @Maykelesser succeeds, but it is problematic, complicated and will give more trouble to understand things than to do by common ways, like a new update in the specific package will auto adjust most things without you need to touch anything

  • I get it. I even tried to use Composer several times, but I always have this command problem not found, and I am using it in the directory where Composer.phar is listed...

  • but then the problem is another! I will try here!

  • @Maykelesser is linux or windows?

  • osx! I got Composer.phar to download in the directory I’d like, but I can’t run any commands on it... it always gives "command not found"!

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.