一つの方法は、次のようにカスタムルートを定義するには、次のようになります。あなたのindexActionあなたが特定のエラーコードのためのアクションに転送しますよりも
resources.routes.error.route = "/error/:id"
resources.routes.error.type = "Zend_Controller_Router_Route"
resources.routes.error.defaults.module = default
resources.routes.error.defaults.controller = error
resources.routes.error.defaults.action = index
resources.routes.error.reqs.id = "\d+"
。たとえば、404エラーの場合:
class ErrorController extends Zend_Controller_Action {
public function indexAction() {
$errorId = $this->_getParam('id', null);
return $this->_forward("error$errorId");
}
public function error404Action() {
echo "error 404";
}
}
これは非常に単純化された例ですが、実行方法を示すには十分なはずです。
転送の代わりに、適切なビュースクリプトをレンダリングするだけです。
class ErrorController extends Zend_Controller_Action {
public function indexAction() {
$errorId = $this->_getParam('id', null);
// e.g. redner error/error404.phtml
$this->_helper->viewRenderer('error$errorId');
}
}
これを処理するためにZendルータを試してみましたか? – emaillenin
ちょっとした提案:私は 'e404Action'(など)を使用します。 – KingCrunch
+1 to genious ^^もしあなたが絶対に 'http:// domain.com/error/404'のようなURLを望むなら、スタティックルートを使用してください。 – Phliplip