我按照this post中的所有步骤进行操作,似乎一切正常,因为我可以将我的新捆绑包安装到我所认为的作曲家的vendor文件夹中。问题是当我尝试在AppKernel.php中初始化bundle时,找不到类。
AppKernel.php
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 AppBundle\AppBundle(),
new abdielcs\ExpandedCollectionBundle\ExpandedCollectionBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
AppKernel.php第20行中的ClassNotFoundException:尝试加载 class" ExpandedCollectionBundle"从命名空间 " abdielcs \ ExpandedCollectionBundle&#34 ;.你忘记了"使用"声明 for" abdielcs \ ExpandedCollectionBundle \ ExpandedCollectionBundle"?
这是autoload_namespaces.php
return array(
'abdielcs\\ExpandedCollectionBundle' => array($vendorDir . '/abdielcs/expanded-collection-bundle'),
'Twig_' => array($vendorDir . '/twig/twig/lib'),
'Sensio\\Bundle\\GeneratorBundle' => array($vendorDir . '/sensio/generator-bundle'),
'Sensio\\Bundle\\DistributionBundle' => array($vendorDir . '/sensio/distribution-bundle'),
'SensioLabs\\Security' => array($vendorDir . '/sensiolabs/security-checker'),
'Psr\\Log\\' => array($vendorDir . '/psr/log'),
'Doctrine\\ORM\\' => array($vendorDir . '/doctrine/orm/lib'),
'Doctrine\\DBAL\\' => array($vendorDir . '/doctrine/dbal/lib'),
'Doctrine\\Common\\Lexer\\' => array($vendorDir . '/doctrine/lexer/lib'),
'Doctrine\\Common\\Inflector\\' => array($vendorDir . '/doctrine/inflector/lib'),
'Doctrine\\Common\\Collections\\' => array($vendorDir . '/doctrine/collections/lib'),
'Doctrine\\Common\\Annotations\\' => array($vendorDir . '/doctrine/annotations/lib'),
'Assetic' => array($vendorDir . '/kriswallsmith/assetic/src'),
);
这是文件夹结构:
这是我的应用程序composer.json:
{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-4": { "": "src/", "SymfonyStandard\\": "app/" }
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.7.*",
"doctrine/orm": "~2.2,>=2.2.3,<2.5",
"doctrine/dbal": "<2.5",
"doctrine/doctrine-bundle": "~1.4",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~3.0,>=3.0.12",
"sensio/framework-extra-bundle": "~3.0,>=3.0.2",
"incenteev/composer-parameter-handler": "~2.0",
"abdielcs/expanded-collection-bundle": "dev-master"
},
"require-dev": {
"sensio/generator-bundle": "~2.3"
},
"scripts": {
"post-root-package-install": [
"SymfonyStandard\\Composer::hookRootPackageInstall"
],
"post-install-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
],
"post-update-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
]
},
"repositories" : [{
"type" : "vcs",
"url" : "https://github.com/abdielcs/ExpandedCollectionBundle.git"
}],
"config": {
"bin-dir": "bin"
},
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "2.7-dev"
}
}
}
捆绑composer.json
{
"name" : "abdielcs/expanded-collection-bundle",
"description" : "Work in progress",
"type" : "symfony-bundle",
"authors" : [{
"name" : "Author name",
"email" : "author email"
}],
"keywords" : [
"collection",
"expanded"
],
"license" : [
"MIT"
],
"require" : {
},
"autoload" : {
"psr-0" : {
"abdielcs\\ExpandedCollectionBundle" : ""
}
},
"extra" : {
"branch-alias" : {
"dev-master" : "0.1.x-dev"
}
}
}
也许我错过了什么?
任何帮助将不胜感激。
答案 0 :(得分:3)
我认为,需要target-dir。因为您使用的是psr0
这仅用于支持传统的PSR-0样式自动加载,并且所有新代码最好使用不带target-dir的PSR-4,并且鼓励使用PSR-0和PHP名称空间的项目转移到PSR-4。 / p>
答案 1 :(得分:3)
在PSR-0中,您的包结构应该完全反映您的命名空间。
因此,要使其工作,请将您的包的内容移至中
/vendor/abdielcs/expanded-collection-bundle/abdielcs/ExpandedCollectionBundle/
/vendor/abdielcs/expanded-collection-bundle/
。
或者,按照@OlivierHenry的指示使用target-dir
。
或者,使用PSR-4几乎每个第三方捆绑包,加上Symfony推荐:
现代捆绑包推荐使用PSR-4自动加载标准