Created
September 21, 2010 10:49
-
-
Save handlename/589529 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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