Php 没有编写器的自动加载类命名空间的问题
在没有Composer的Symfony2项目中注册捆绑包时,我遇到了一些问题 在我的公司,由于代理关系,我不能使用Composer 我成功地安装了Php 没有编写器的自动加载类命名空间的问题,php,symfony,autoload,vendor,Php,Symfony,Autoload,Vendor,在没有Composer的Symfony2项目中注册捆绑包时,我遇到了一些问题 在我的公司,由于代理关系,我不能使用Composer 我成功地安装了FOSUserBundle,所以我不明白为什么它不能与KnpSnappyBundle一起工作 我的供应商树: vendor/ friendofsymfony/ user-bundle/ FOS/ UserBundle/ FOSUser
FOSUserBundle
,所以我不明白为什么它不能与KnpSnappyBundle
一起工作
我的供应商
树:
vendor/
friendofsymfony/
user-bundle/
FOS/
UserBundle/
FOSUserBundle.php
knplabs/
knp-snappy-bundle/
Knp/
Bundle/
SnappyBundle/
KnpSnappyBundle.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;
<?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');
}
}
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?
Myapp/autoload.php
:
vendor/
friendofsymfony/
user-bundle/
FOS/
UserBundle/
FOSUserBundle.php
knplabs/
knp-snappy-bundle/
Knp/
Bundle/
SnappyBundle/
KnpSnappyBundle.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;
<?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');
}
}
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?
错误消息:
vendor/
friendofsymfony/
user-bundle/
FOS/
UserBundle/
FOSUserBundle.php
knplabs/
knp-snappy-bundle/
Knp/
Bundle/
SnappyBundle/
KnpSnappyBundle.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;
<?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');
}
}
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?
请帮忙 好的,我找到了
因此,这是一个很好的过程,但我忘记了清除缓存
php app/consoloe ca:cl -e=dev
在那之后,我仍然有一个错误:
Fatal error: Interface 'Knp\Snappy\GeneratorInterface' not found in /vendor/bundles/Knp/Bundle/SnappyBundle/Snappy/LoggableGenerator.php on line 14
因为没有Composer,KnpSnappyBundle的一部分丢失了,所以我在GitHub上添加了我的供应商:
vendor/
knplabs/
knp-snappy-bundle/
Knp/
Bundle/
SnappyBundle/
KnpSnappyBundle.php
Snappy/
Exeption/
AbstractGenerator.php
GeneratorInterface.php
Image.php
Pdf.php
Process.php
一切正常,我没有修改我的app/autoload.php
和我的app/AppKernel.php
目前问题已经解决
作曲家:
composer require knplabs/knp-snappy
composer require h4cc/wkhtmltopdf-amd64
use Knp\Snappy\Pdf;
$knpSnappyPdf = new Pdf();
$knpSnappyPdf->setBinary(__DIR__ . '/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');
$html = $this->renderView('Pdf/template.html.twig', [
...
]);
$data = $knpSnappyPdf->getOutputFromHtml($html);
Symfony用法:
composer require knplabs/knp-snappy
composer require h4cc/wkhtmltopdf-amd64
use Knp\Snappy\Pdf;
$knpSnappyPdf = new Pdf();
$knpSnappyPdf->setBinary(__DIR__ . '/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');
$html = $this->renderView('Pdf/template.html.twig', [
...
]);
$data = $knpSnappyPdf->getOutputFromHtml($html);
代码:
composer require knplabs/knp-snappy
composer require h4cc/wkhtmltopdf-amd64
use Knp\Snappy\Pdf;
$knpSnappyPdf = new Pdf();
$knpSnappyPdf->setBinary(__DIR__ . '/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');
$html = $this->renderView('Pdf/template.html.twig', [
...
]);
$data = $knpSnappyPdf->getOutputFromHtml($html);
此捆绑包解决了我在基于绝对路径的本地图像方面的问题。第一件事:“在我的公司,由于代理关系,我无法使用Composer”?你能再解释一下吗?考虑到你得到的是什么样的错误信息?@EliasVanOotegem:我尝试过所有的方法,但都没有效果,代理似乎非常复杂,不可能绕过。Cerad:我已经编辑了我的问题。您仍然可以使用Composer自动加载,而无需下载Composer的依赖项。您是否检查了bundle目录的权限?