最善の策は、カスタム エラー ページを作成し、オプションでカスタム エラー ハンドラを作成してエラーを警告することです。
まず、カスタム エラー ページを作成します/path/to/project/config/error/error.html.php
。symfony は、エラーページが存在する場合、それ自体の代わりに自動的にエラーページを使用します。
もう少し高度にしたい場合は、イベント リスナーを追加して、キャッチされていない例外を処理できます。これを行うには、/path/to/project/config/ProjectConfiguration.class.php
次のようにリスナーを編集して追加します。
class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
//...
$this->dispatcher->connect('application.throw_exception', array($this, 'listenToException'));
}
public function listenToException(sfEvent $event)
{
$handler = new myExceptionHandler($event);
$handler->doSomethingHere();
}
}
あとは、パラメータを除く独自のmyExceptionHandler
クラスを作成するだけです。sfEvent $event
ここでやりたいことは何でもできます。エラーが発生したことを知らせるために、自分自身に電子メールを送信することをお勧めします。
以下に簡単な例を示します。
class myExceptionHandler
{
protected $event;
public function __construct(sfEvent $event)
{
$this->event = $event;
}
protected function getMailer()
{
return sfContext::getInstance()->getMailer();
}
public function notify()
{
$subject = 'Uncaught Exception';
$body = $this->event->getSubject();
$mailer = $this->getMailer();
$mailer->composeAndSend('root@yourserver.com', 'you@youremail.com', $subject, $body);
}
}
この例では$handler->notify()
、プロジェクト構成から呼び出すだけで、スタック トレースがメールで送信されます。$_SERVER
変数などの他の情報を含めることもできます...