1

因此,我创建了一个类,该类扩展Symfony\Bundle\FrameworkBundle\Routing\Router 并定义为我在配置中使用的默认值router.class: My\Bundle\Router\Class,但是现在每次我更改诸如路由模式或名称之类的简单内容时,我都会得到...

致命错误:在第 312 行的 /.../app/cache/dev/classes.php 中的非对象上调用成员函数 get()

在那一行中有:

$this->collection = $this->container->get('routing.loader')->load($this->resource, $this->options['resource_type']);

我错过了什么?

4

1 回答 1

2

$this->container在课堂上是私有的Router。你不能直接访问它。

您需要明确地使其可访问:

/**
 * Router 
 */
class Router extends BaseRouter
{
    protected $container;

    /**
     * Constructor.
     *
     * @param ContainerInterface $container A ContainerInterface instance
     * @param mixed              $resource  The main resource to load
     * @param array              $options   An array of options
     * @param RequestContext     $context   The context
     * @param array              $defaults  The default values
     */
    public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null, array $defaults = array())
    {
        $this->container = $container;

        parent::__construct($container, $resource, $options, $context, $defaults);
    }
}
于 2012-12-16T13:33:49.913 回答