1
class HelloController
{
    /**
     * @Route("/", name="hello")
     */
    public function indexAction($name)
    {
        return new Response($name);
    }
}

我想在不使用路由的情况下将变量 $name 传递给 indexAction。

在文档中我发现:

services:
    # ...

    # explicitly configure the service
    AppBundle\Controller\HelloController:
        public: true
        tags:
            # add multiple tags to control 
            - name: controller.service_arguments
              action: indexAction
              argument: logger
              # pass this specific service id
              id: monolog.logger.doctrine

这向我们展示了如何将另一个服务传递给控制器​​,但是如何传递一个简单的变量呢?

4

1 回答 1

0

在 routing.yml 中试试这个:

defaults:
        _controller: AppBundle:Hello:index
        name:        "WhatYouWantToPass"
于 2017-06-13T07:25:55.950 回答