本文介绍了无法实例化抽象类... appDevDebugProjectContainer.php-Symfony2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我昨天刚安装了 apc ,现在出现此错误:
I have just installed yesterday apc and I am now getting this error:
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'));
}
有人知道它的意思是什么,我能做什么吗?
Does any one know what does it mean and what I can do with it?
services.yml
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类代码:
a bit of MenuBuilder Class code:
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规则实例化抽象类!
Well the error is pretty self-explanatory. You cannot instantiate an Abstract Class as per OOP rules !
您的MenuBuilder
是 abstract
类,您尝试使用 new
关键字实例化.
Your MenuBuilder
is an abstract
class and you are trying to instantiate with a new
keyword which is not possible.
这篇关于无法实例化抽象类... appDevDebugProjectContainer.php-Symfony2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!