【问题标题】:How to properly override the default router?如何正确覆盖默认路由器?
【发布时间】:2012-12-16 13:03:38
【问题描述】:

所以我创建了一个扩展 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']);

我错过了什么?

【问题讨论】:

    标签: symfony


    【解决方案1】:

    $this->containerRouter 类中是私有的。你不能直接访问它。

    你需要明确地访问它:

    /**
     * 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);
        }
    }
    

    【讨论】:

    • 谢谢你们!这就是问题所在,“私人”......它让我发疯,我没有看到它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 2023-04-01
    • 2020-09-22
    • 2011-06-19
    • 2017-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多