プロジェクトにsymfony 2を使用しています。私は各関数の前にいくつかのチェックを行うコントローラーを持っています。私が望むのは、symfony がそのコントローラーへのすべてのリクエストでその関数を起動するようにすることです。例えば
class ChatController extends Controller
{
public function put()
{
$user = $this->getUser();
$this->checkSomething(); //just a custom function
$this->checkSomethingElse(); //another custom function
// do something
}
public function get()
{
$user = $this->getUser();
$this->checkSomething(); //just a custom function
$this->checkSomethingElse(); //another custom function
// do something
}
}`
と同じことを達成したい:
class ChatController extends Controller
{
private $user;
public function init()
{
$this->user = $this->getUser();
$this->checkSomething(); //just a custom function
$this->checkSomethingElse(); //another custom function
}
public function put()
{
//here i can access $this->user
// do something
}
public function get()
{
//here i can access $this->user
// do something
}
}`
したがって、基本的に私が望むのは、関数をコンストラクターのように動作させることです。これは Symfony2 で実行できますか?