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

时间:2013-09-11 07:29:06

标签: 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'));
}

有没有人知道这是什么意思,我能用它做什么?

services.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;
    }
}

2 个答案:

答案 0 :(得分:11)

错误是非常明显的。根据OOP规则,您不能实例化抽象类!

您的MenuBuilder abstract 类,并且您尝试使用 new 关键字进行实例化,这是不可能的。

答案 1 :(得分:2)

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

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