3

我昨天刚刚安装了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;
    }
}
4

2 回答 2

11

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

MenuBuilder是一个abstract类,你试图用一个new不可能的关键字来实例化。

于 2013-09-11T07:32:17.970 回答
2

如果您的 MenuBuilder 类在某些时候是抽象的,而您将其更改为具体的类,则 APC 可能仍然潜伏着旧版本(在内存中)。

尝试重新启动您的网络服务器。

于 2014-10-24T03:42:54.077 回答