php - 无法实例化抽象类...在 appDevDebugProjectContainer.php - Symfony2

标签 php symfony apc

我昨天刚刚安装了 apc,现在我收到这个错误:

FatalErrorException: Error: Cannot instantiate abstract class
ACME\WebBundle\Menu\MenuBuilder in
/var/www/app/cache/dev/appDevDebugProjectContainer.php line 743

在那一行中有:

protected function getEposMain_MenuBuilderService()
{
    return $this->services['epos_main.menu_builder'] = new \ACME\WebBundle\Menu\MenuBuilder($this->get('knp_menu.factory'));
}

有谁知道这是什么意思以及我可以用它做什么?

服务.yml

services:
    epos_main.menu_builder:
        class: ACME\WebBundle\Menu\MenuBuilder
        arguments: ["@knp_menu.factory"]

    epos_main.menu.main:
        class: Knp\Menu\MenuItem # the service definition requires setting the class
        factory_service: epos_main.menu_builder
        factory_method: createMainMenu
        arguments:
            - @request
            - @twig
            - 'ACMEWebBundle:Menu:menu.html.twig'
        scope: request # needed as we have the request as a dependency here
        tags:
            - { name: knp_menu.menu, alias: main } # The alias is what is used to retrieve the menu

    epos.twig.epos_extension:
        class: ACME\WebBundle\Twig\ePOSTwigExtension
        tags:
            - { name: twig.extension }

一些 MenuBuilder 类代码:

namespace ACME\WebBundle\Menu;

use Knp\Menu\FactoryInterface;
use Symfony\Component\HttpFoundation\Request;

class MenuBuilder
{
    private $factory;

    /**
     * @param FactoryInterface $factory
     */
    public function __construct(FactoryInterface $factory)
    {
        $this->factory = $factory;
    }

    public function createMainMenu(Request $request)
    {

        $menu = $this->factory->createItem('root');
        $menu->setChildrenAttribute('class', 'nav');
        ...
        ...
        return $menu;
    }
}

最佳答案

这个错误是不言自明的。您不能根据 OOP 规则实例化抽象类!

您的 MenuBuilder 是一个抽象 类,您正在尝试用一个new 不可能的关键字。

关于php - 无法实例化抽象类...在 appDevDebugProjectContainer.php - Symfony2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18735149/

相关文章:

php - 如何从mySQL表中获取格式化的时间戳?

php - 什么是更快地准备一个 sql 查询以使查询简约或做很多喜欢?

javascript - 如何在 Symfony2 的 Bootstrap 模态弹出窗口中动态显示数据

symfony - 子文件夹中的刺激 Controller 在 Symfony 中不起作用

symfony - 如何使用 Symfony2 配置 APC

php - 需要根据给定的句子创建一个随机句子

php - 如何获取查询次数最少的帖子列表和关联的标签

php - Symfony 2/PHP 比较数组中对象的差异?

php - 如何在不使 Apache 崩溃的情况下清除 APC 缓存?

php - 什么是APC的最佳PHP处理程序?