오류 템플릿은 CMS에만 포함됩니다. 프레임 워크는 메시지가있는 일반 텍스트로 HTTP 응답 코드를 반환합니다.
내가 너무 내 자신의 프레임 워크 전용 프로젝트를 시작했습니다이 내 솔루션입니다 :
[routes.yml]
---
Name: rootroutes
---
Director:
rules:
'': 'MyController'
'$URLSegment': 'MyController'
[MyController에]
class MyController extends Controller {
private static $url_handlers = array(
'$URLSegment' => 'handleAction',
);
public function index() {
return $this->httpError(404, "Not Found");
}
/**
* Creates custom error pages. This will look for a template with the
* name ErrorPage_$code (ie ErrorPage_404) or fall back to "ErrorPage".
*
* @param $code int
* @param $message string
*
* @return SS_HTTPResponse
**/
public function httpError($code, $message = null) {
// Check for theme with related error code template.
if(SSViewer::hasTemplate("ErrorPage_" . $code)) {
$this->template = "ErrorPage_" . $code;
} else if(SSViewer::hasTemplate("ErrorPage")) {
$this->template = "ErrorPage";
}
if($this->template) {
$this->response->setBody($this->render(array(
"Code" => $code,
"Message" => $message,
)));
$message =& $this->response;
}
return parent::httpError($code, $message);
}
}
[ ErrorPage.ss]
<h1>$Code</h1>
<p>$Message</p>
ErrorPage_404.ss, ErrorPage_500.ss 등을 사용하여보다 구체적인 오류 템플릿을 만들 수도 있습니다.
죄송합니다. 기본적인 예일뿐입니다. 자신의 앱에서 다르게 경로를 지정하려는 경우 404가 handleAction 또는 handleRequest에 표시 될 가능성이 큽니다. – micmania1