contenir/errors-laminas-mvc 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

contenir/errors-laminas-mvc

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 ?>.

contenir/errors-laminas-mvc 适用场景与选型建议

contenir/errors-laminas-mvc 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 53 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 contenir/errors-laminas-mvc 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 contenir/errors-laminas-mvc 我们能提供哪些服务?
定制开发 / 二次开发

基于 contenir/errors-laminas-mvc 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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