2016-04-29 120 views
-2

我有我想打電話從一個控制器的功能,另一個控制器

class examController{ 
    public function regMail(){ 

    } 
} 

我想在authController

class authController{ 
    // i want regMail() here 

} 
+0

控制器應包含操作。發送郵件看起來像是一項服務的工作。 http://symfony.com/doc/current/book/service_container.html –

+0

把你的動作改爲模態,然後從控制器調用它 – Poria

+2

你應該看看文檔,並嘗試瞭解如何使用服務以及服務是什麼容器由Symfony提供。 – COil

回答

1

調用regMail()來這樣做,你有2個解決方案:

1 - 使用forwarding(良好做法);

//In your controllor 
    public function indexAction($name) { 

     $response = $this->forward('AppBundle:Something:fancy', array(
      'name' => $name, 
      'color' => 'green', 
    )); 

     // ... further modify the response or return it directly 

     return $response; 
    } 

2 - 將您的控制器定義爲服務(壞習慣);

嘗試看看這個post瞭解更多細節和(當然)官方文檔。 祝你好運^^!

相關問題