1

我最近创建了一个名为 PublishBannerController.php 的控制器,它是对以前的控制器的剪切和粘贴,所有各个部分都相应地进行了调整。唯一的问题是,当我尝试加载它时出现此错误:

FatalErrorException: Error: Class 'Me\MyBundle\Controller?ublishBannerController' not found in /.../public_html/app/cache/dev/appDevDebugProjectContainer.php line 3190

我已将出现的正方形替换为 ? 因为正方形真的与 stackOverflows 编辑器混淆了。Symfony 2 解析器似乎将包含 \P 的路径转换为表示的特殊字符。正如您在 appDevDebugProjectContainer.php 中看到的那样,它在 \P 的任何位置都会对其进行转换,即使在评论中也是如此。它包含 _P 等的任何地方都可以。

/*
* Gets the 'me.controller.publishbanner' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return Me\MyBundle\Controller?ublishBannerController A Me\MyBundle\Controller?ublishBannerController instance.
*/
protected function getMe_Controller_PublishbannerService()
{
$this->services['me.controller.publishbanner'] = $instance = new \Me\MyBundle\Controller?ublishBannerController();

$instance->setContainer($this);

return $instance;
}

这是我的 routing.yml

me_site_publishbanner:
    pattern:  /publishbanner
    defaults: { _controller: me.controller.publishbanner:indexAction }

和 services.yml

me.controller.publishbanner:
    class:  "Me\MyBundle\Controller\PublishBannerController"
    shared: true
    calls:
        - [ setContainer, ["@service_container"] ]

我在某处犯了错误还是这是 Symfony 2 中的错误?您基本上不允许创建以P开头的控制器名称吗?

显然,这是一个 Unicode 问题并且与此有关:http: //php.net/manual/en/regexp.reference.unicode.php

我在我的 php.ini 中有这个设置:

default_charset = "UTF-8"

我只是没想到会在 Symfony 2 中遇到这种问题。

4

1 回答 1

3

不要在 yaml 文件中使用双引号作为字符串分隔符。看起来,使用双引号,\ 字符被转换为它们的转义值。

根本不需要对类名使用任何引号。

如果您确实想引用 @service 之类的内容以避免警告某些损坏的 yaml 处理器问题,请使用单引号。

于 2013-08-21T15:37:22.593 回答