1

I've got some problems for register a bundle in a Symfony2 project without Composer.
In my company I can't use Composer due to proxy.

I succesfully install FOSUserBundle so I don't understand why it doesn't work with KnpSnappyBundle...

My vendor tree :

vendor/
    friendofsymfony/
        user-bundle/
            FOS/
                UserBundle/
                    FOSUserBundle.php
    knplabs/
        knp-snappy-bundle/
            Knp/
                Bundle/
                    SnappyBundle/
                        KnpSnappyBundle.php

My app/autoload.php :

<?php

use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;

/**
 * @var ClassLoader $loader
 */
$loader = require __DIR__.'/../vendor/autoload.php';
$loader->add('FOS', __DIR__.'/../vendor/friendsofsymfony/user-bundle');
$loader->add('Knp', __DIR__.'/../vendor/knplabs/knp-snappy-bundle');

AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

return $loader;

My app/AppKernel.php :

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new My\Bundle\OwnBundle\MyOwnBundle(),
            new FOS\UserBundle\FOSUserBundle(),
            new Knp\Bundle\SnappyBundle\KnpSnappyBundle()
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
    }
}

The error message :

ClassNotFoundException: Attempted to load class "KnpSnappyBundle" from namespace "Knp\Bundle\SnappyBundle" in C:\xampp\htdocs\my-project\app\AppKernel.php line 25. Do you need to "use" it from another namespace?

Please help !

5
  • 1
    First things first: "In my company I can't use Composer due to proxy"? Could you please explain this a bit more? Given that composer can be used from behind a proxy Commented Jul 22, 2014 at 13:54
  • What sort of error message are you getting? Commented Jul 22, 2014 at 14:30
  • @EliasVanOotegem : I've ever try everything and nothing works, the proxy seems really complex and it's impossible to get around. Cerad : I've edit my question. Commented Jul 22, 2014 at 14:37
  • You can still use Composer autoloading without downloading dependencies by composer. Commented Jul 22, 2014 at 15:30
  • did you check the permission of the bundle dir? Commented Jul 22, 2014 at 15:36

2 Answers 2

3

OK I found it !

So it was the good procedure but I forget to clear the cache.

php app/consoloe ca:cl -e=dev

After that I've still got an error :

Fatal error: Interface 'Knp\Snappy\GeneratorInterface' not found in /vendor/bundles/Knp/Bundle/SnappyBundle/Snappy/LoggableGenerator.php on line 14

Because without Composer a part of the KnpSnappyBundle is missing, so I download the missing directories on GitHub and add in my vendor :

vendor/
    knplabs/
        knp-snappy-bundle/
            Knp/
                Bundle/
                    SnappyBundle/
                        KnpSnappyBundle.php
                Snappy/
                    Exeption/
                    AbstractGenerator.php
                    GeneratorInterface.php
                    Image.php
                    Pdf.php
                    Process.php

Everything works, I didn't modify my app/autoload.php and my app/AppKernel.php.

Sign up to request clarification or add additional context in comments.

Comments

0

Currently the problem solved.

Composer:

composer require knplabs/knp-snappy

composer require h4cc/wkhtmltopdf-amd64

Symfony use:

use Knp\Snappy\Pdf;

Code:

$knpSnappyPdf = new Pdf();

$knpSnappyPdf->setBinary(__DIR__ . '/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');

$html = $this->renderView('Pdf/template.html.twig', [
    ...
]);

$data = $knpSnappyPdf->getOutputFromHtml($html);

This bundle solved my problem with local images based on absolute path.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.