我想在我的應用程序中使用自定義幫助程序。如何在symfony 2中聲明幫助程序
我創建的文件Myhelper.php捆綁/助手/ Myhelper.php與
namespace Project\Bundle\Helper;
class Myhelper {
public function __construct($doctrine) {
$this->doctrine = $doctrine;
}
function testMyHelper() {
return "hi";
}
}
我試圖把它叫在我的控制器:
$myHelper = $this->get('Myhelper');
但我有以下錯誤:
An exception has been thrown during the rendering of a template ("You have requested a non-existent service "myhelper".")
我必須在特定的配置文件中聲明它嗎?
Thx
最後我用它作爲服務,它是從任何控制器填充數據庫中的通知 – Paul