定制 contenir/errors-laminas-mvc 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

contenir/errors-laminas-mvc

最新稳定版本:v0.3.0

Composer 安装命令:

composer require contenir/errors-laminas-mvc

包简介

Laminas MVC adapter for contenir/errors — swaps the default error rendering with admin-authored per-status pages.

README 文档

README

Laminas MVC adapter for contenir/errors.

Replaces the framework's default 4xx/5xx rendering with admin-authored per-status pages when configured. Non-invasive on first install — when the admin hasn't authored a page for a given status, the framework's default rendering proceeds unchanged.

Install

composer require contenir/errors-laminas-mvc

The Module is auto-registered by laminas/laminas-component-installer.

Configure

Point the package at a shared error-pages file (the same path the admin writes to) and optionally wire a PSR-3 logger:

// config/autoload/errors.global.php

return [
    'errors' => [
        'file'          => realpath(__DIR__ . '/../..') . '/configs/errors.local.php',
        'view_template' => 'contenir/errors/fault',  // override to use a Site-owned template
        'logger'        => 'log.psr3',                // optional PSR-3 service ID
    ],
];

file is required. view_template defaults to the package's shipped contenir/errors/fault.phtml (uses the .fault BEM block, no scripts, <meta name="robots" content="noindex">, single "Return home" link). logger may be null, a service ID resolvable from the container, or a Psr\Log\LoggerInterface instance.

How it works

The ErrorListener attaches at MvcEvent::EVENT_RENDER and EVENT_RENDER_ERROR at priority 100. By the time RENDER fires, the response status is already settled (RouteNotFoundStrategy has set 404, ExceptionStrategy has set 500, or a controller has called setStatusCode(403)). The listener:

  1. Logs the 4xx/5xx via the optional PSR-3 logger (info() for 4xx, error() for 5xx, with the exception in context if available).
  2. If the repository has a non-empty page for the status, swaps the result ViewModel template + variables (status, title, body) and marks it terminal so the layout is bypassed.
  3. Otherwise leaves the existing render path untouched.

Override the view

To brand the page beyond what's possible in the body field, set errors.view_template to your own template name:

'errors' => [
    'view_template' => 'site/error-page',
],

Your template receives:

Variable Type Notes
$status int HTTP status code (e.g. 404)
$title string Plain text written by the admin
$body string Sanitized HTML fragment (inline only) — render raw

The body is trusted — sanitization is the writer's responsibility (see the admin-side wiring in the consuming CMS). Render with <?= $body ?>.

统计信息

  • 总下载量: 14
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固