我已经用symfony 2.3创建了一个包,但是在这个例子中(因为我的老师问我)在src/文件夹之外,我使用了../symfony/fuentes/NameBundle而不是../symfony/src/NameBundle。新行出现在AppKernel中,我的新包出现在routing.yml上,但是当我试图启动服务器时
Bundle generation
Generating the bundle code: OK
Checking that the bundle is autoloaded: FAILED
Confirm automatic update of your Kernel [yes]?
Enabling the bundle inside the Kernel: OK
Confirm automatic update of the Routing [yes]?
Importing the bundle routing resource: OK
The command was not able to configure everything automatically.
You must do the following changes manually.
- Edit the composer.json file and register the bundle
namespace in the "autoload" section:我已经编辑了autoload,并尝试了很多事情(在这里寻找),但它似乎总是相同的错误。
C:\Users\Akenateb\Documents\UOC\AULAMENTOR\Symfony>php app/console server:run 127.0.0.1:8080
PHP Fatal error: Class 'AulaMentor\ExdosBundle\AulaMentorExdosBundle' not found in C:\Users\Akenateb\Documents\UOC\AULAMENTOR\Symfony\app\AppKernel.php on line 20有人能帮我吗?我真的被困住了。提前谢谢。
发布于 2015-10-30 15:35:31
首先,我要感谢那些回答的人。如果我们想在'src‘>文件夹外创建一个包,例如在'fuentes’> '..Symfony/fuentes‘>中,我们必须这样做。
如果您已经用'generate: bundle‘创建了,我建议您接受当生成器询问您是否要创建完整的结构时,如果您已经用生成器创建了一个包,请执行步骤3。
1-确保您已经在AppKernel中注册了包,并且它存在于以下一行:
新YourProject\NameprojectBundle\YourProjectNameprojectBundle(),
2-确保向应用程序/配置/路由添加了一个路由,并且“routing.yml”有新的包路由,如下所示(您可以在url中添加一个前缀,在本例中是fuentes):
your_project_name:
**resource: "@YourProjectNameprojectBundle/Resources/config/routing.yml"** **prefix: /fuentes**3-我们编辑‘app/autooload.php’,并添加以下一行:
realpath(__DIR__.'/../fuentes')); $ $loader->add('YourProject‘)
最后,我们可以使用命令行更新资产: php应用程序/控制台资产:安装web
希望这对某人有帮助。
诚挚的问候。
发布于 2015-10-28 12:40:18
正如评论中所说的那样:
Edit the composer.json file and register the bundle namespace in the "autoload" sectionsrc文件夹将使用PSR约定自动加载。如果在src文件夹之外设置类,则还必须声明它们。
发布于 2015-10-29 09:15:59
在composer.json文件中,您可以在autoload部分中添加另一个元素。下面是一个我认为适用于您的用例的示例:
"autoload": {
"psr-0": {
"NameBundle\\": "fuentes/",
"": "src/"
}
},https://stackoverflow.com/questions/33391274
复制相似问题