【发布时间】:2014-09-13 09:20:27
【问题描述】:
在没有 Composer 的情况下在 Symfony2 项目中注册捆绑软件时遇到了一些问题。
在我的公司,由于代理,我无法使用 Composer。
我成功安装了FOSUserBundle,所以我不明白为什么它不适用于KnpSnappyBundle...
我的vendor 树:
vendor/
friendofsymfony/
user-bundle/
FOS/
UserBundle/
FOSUserBundle.php
knplabs/
knp-snappy-bundle/
Knp/
Bundle/
SnappyBundle/
KnpSnappyBundle.php
我的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;
我的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');
}
}
错误信息:
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?
请帮忙!
【问题讨论】:
-
第一件事:“在我的公司,由于代理,我无法使用 Composer”?你能再解释一下吗?鉴于composer can be used from behind a proxy
-
你得到什么样的错误信息?
-
@EliasVanOotegem :我什么都试过了,但没有任何效果,代理似乎真的很复杂,而且不可能绕过。 Cerad:我已经编辑了我的问题。
-
您仍然可以使用 Composer 自动加载,而无需由 composer 下载依赖项。
-
你检查过bundle目录的权限吗?
标签: php symfony autoload vendor