我从symfony 3.4.17开始并尝试学习它。我遵循一个教程: https://openclassrooms.com/fr/courses/3619856-developpez-votre-site-web-avec-le-framework-symfony/3621961-les-services-theorie-et-creation
我创建了一个新的bundle,并生成了控制器和视图,但是当我尝试运行我的应用程序时,它使我出错
找不到控制器:服务“ OCCoreBundle”不存在。
我检查了所有文件,没有看到任何错误。你能帮我找到它吗?
非常感谢我的帮助,如果我的英语不太好,很抱歉:)
我的代码的某些部分(如果需要其他文件,请告诉我):
// app/Ressources/config/routing.yml
oc_platform:
resource: "@OCPlatformBundle/Resources/config/routing.yml"
prefix: /platform
oc_core:
resource: "@OCCoreBundle/Resources/config/routing.yml"
prefix: /
// app/AppKernel.php
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
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 Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new OC\PlateformBundle\OCPlateformBundle(),
new OC\CoreBundle\OCCoreBundle()
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
if ('dev' === $this->getEnvironment()) {
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
}
}
return $bundles;
}
// src/OC/CoreBundle/Ressources/config/routing.yml
core_homepage:
path: /
defaults: { _controller: OCCoreBundle:index }
// src/OC/CoreBundle/Controller/CoreController.php
<?php
namespace OC\CoreBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class CoreController extends Controller
{
public function indexAction($page)
{
}
}
// src/OC/CoreBundle/OCCoreBundle.php
<?php
namespace OC\CoreBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class OCCoreBundle extends Bundle
{
}
答案 0 :(得分:1)
我发现了我的错误,我只是在走路线时忘了说我想要Core控制器。 所以在我的代码中,我用:
修改了Core的路由yml。// src/OC/CoreBundle/Ressources/config/routing.yml
oc_core_homepage:
path: /
defaults:
_controller: OCCoreBundle:Core:index
我还为CoreController添加了相同内容:
// src/OC/CoreBundle/Controller/CoreController.php
<?php
namespace OC\CoreBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class CoreController extends Controller
{
public function indexAction()
{
return $this->render('OCCoreBundle:Core:layout.html.twig');
}
}
谢谢Anjana Silva尝试帮助我^^,我将把我的帖子解决:)