2017-06-13 150 views
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 

這表明我們如何通過其他服務來控制,但如何通過一個簡單的變量?

回答

0

嘗試這裏面的routing.yml:

defaults: 
     _controller: AppBundle:Hello:index 
     name:  "WhatYouWantToPass" 
相關問題