Skip to content

Instantly share code, notes, and snippets.

@handlename
Created September 21, 2010 10:49
Show Gist options
  • Save handlename/589529 to your computer and use it in GitHub Desktop.
Save handlename/589529 to your computer and use it in GitHub Desktop.
<?php
class myApiActions extends sfActions
{
// ...(中略)...
/*
* 条件真のときにエラーレスポンスを返す
*
* @param bool $condition 条件。これが真ならエラー
* @param int $status ステータスコード
* @param string $message エラーメッセージ
*/
final public function forwardErrorIf($condition, $status = 500, $message = '')
{
if($condition == true)
{
$this->forwardError($status, $message);
}
}
/*
* 条件偽のときにエラーレスポンスを返す
*
* @param bool $condition 条件。これが偽ならエラー
* @param int $status ステータスコード
* @param string $message エラーメッセージ
*/
final public function forwardErrorUnless($condition, $status = 500, $message = '')
{
if($condition == false)
{
$this->forwardError($status, $message);
}
}
/*
* エラーレスポンスを返す
*
* @param int $status ステータスコード
* @param string $message エラーメッセージ
*/
final public function forwardError($status = 500, $message = '')
{
$this->logMessage($message, 'err');
$this->getUser()->setFlash('data', array('status' => $status));
$this->getController()->forward('shared', 'error');
throw new sfStopException();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment