sirgrimorum/pages
Composer 安装命令:
composer require sirgrimorum/pages
包简介
Content manager by pages for Laravel 5.6
关键字:
README 文档
README
Database-driven page and section manager for Laravel. Define structured pages composed of independent sections, control access per page or section via policy closures, inject dynamic content from Eloquent collections, and wire everything into AutoMenu navigation — all from configuration.
Features
- Database-backed pages and sections — manage content via CRUD admin (requires sirgrimorum/crudgenerator)
- Composable sections — pages are assembled from ordered, independently-controlled sections
- Policy-based access control — flexible wildcard pattern rules per page and section name
- Special sections — inject dynamic content (Blade templates, model collections, method results) into page content via
{%%name%%}placeholders - AutoMenu integration — automatically populate a menu with all accessible pages
- Localized routes — optional URL localization out of the box
- Blade directives — render pages and sections from any template
- Seeder generation — dump pages/sections to a seed file with one command
Requirements
- PHP >= 8.2
- Laravel >= 9.0
- sirgrimorum/transarticles ^1.3
- sirgrimorum/crudgenerator ^3.8
Installation
composer require sirgrimorum/pages
Run migrations
php artisan migrate
Creates the paginas (pages) and sections tables.
Publish configuration
php artisan vendor:publish --provider="Sirgrimorum\Pages\PagesServiceProvider" --tag=config
Publishes config/sirgrimorum/pages.php.
Publish language files (optional)
php artisan vendor:publish --provider="Sirgrimorum\Pages\PagesServiceProvider" --tag=lang
Publish views (optional)
php artisan vendor:publish --provider="Sirgrimorum\Pages\PagesServiceProvider" --tag=views
Register CRUD configurations
php artisan pages:registercrud
Registers the Pagina and Section models with CrudGenerator so they can be managed via the admin interface.
Configuration
config/sirgrimorum/pages.php
Routing
'with_routes' => true, // Auto-register package routes 'localized' => true, // Prefix routes with locale: /{locale}/... 'group_name' => 'paginas.', 'group_prefix' => '', // Additional URL prefix
View layout
'extends' => 'layouts.app', // Parent Blade layout 'content' => 'content', // @section name for page content
Asset injection
'js_section' => 'scripts', // @push stack name for JS 'css_section' => 'styles', // @push stack name for CSS
Access control policies
Define access rules using name patterns. More specific patterns take precedence.
'paginas_policies' => [ '_general' => fn() => true, // all pages (default) 'admin*' => fn() => Auth::user()?->isAdmin(), // pages starting with "admin" '*private' => fn() => Auth::check(), // pages ending with "private" '*secret*' => fn() => false, // pages containing "secret" 'dashboard' => fn() => Auth::check(), // exact match ], 'sections_policies' => [ '_general' => fn() => true, ],
Pattern matching rules (in order of precedence):
pageName— exact match*name— ends with "name"name*— starts with "name"*name*— contains "name"_general— catch-all
Special sections
Special sections let you inject dynamic content into pages using {%%name%%} placeholders in page templates.
'special_sections' => [ 'featured_posts' => [ 'type' => 'collection', // 'simple', 'collection', or 'model' 'isModel' => App\Models\Post::class, 'function' => 'getFeatured', // Method to call on the model 'template' => 'partials.featured_post', // Blade template for each item ], 'site_notice' => [ 'type' => 'simple', 'template' => 'partials.site_notice', // Just renders a Blade view ], ],
In your page template (stored in the database):
<div class="main-content">{%%content%%}</div> <aside>{%%featured_posts%%}</aside> <div class="notice">{%%site_notice%%}</div>
Usage
Render a page
{{-- Render the first accessible page --}} @load_page() {{-- Render a specific page by name --}} @load_page('home') {{-- Render a page with custom config --}} @load_page('home', 'sirgrimorum/pages')
Render a single section
@load_section('hero-banner')
Build an AutoMenu config with pages
use Sirgrimorum\Pages\Pages; // Inject all accessible pages into position 2 of the left nav $menuConfig = Pages::getAutoMenuConfig(2, 'izquierdo', config('sirgrimorum/menus/main')); echo AutoMenu::buildAutoMenu('main-nav', '', $menuConfig);
Check access programmatically
use Sirgrimorum\Pages\Pages; if (Pages::hasAccessToPagina($page)) { // user can see this page } if (Pages::hasAccessToSection($section)) { // user can see this section }
API Reference
Pages::buildPage()
Pages::buildPage( mixed $name = '', // Page name, ID, object, or '' for first allowed mixed $config = '', // Config array or path mixed $sections = '' // Sections array override ): string
Returns the rendered HTML for the page, including all its sections.
Pages::buildSection()
Pages::buildSection(mixed $name, mixed $config = ''): string
Returns the rendered HTML for a single section.
Pages::getFirstAllowedPage()
Pages::getFirstAllowedPage(): ?Pagina
Returns the first page the current user is allowed to view.
Pages::getAutoMenuConfig()
Pages::getAutoMenuConfig( int $offset, // Position to insert pages in the menu array string $lado, // Menu side: 'izquierdo' or 'derecha' array $automenu // Existing menu structure to inject into ): array
Blade directives
@load_page(string $name = '', mixed $config = '') @load_section(string $name, mixed $config = '')
Artisan Commands
| Command | Description |
|---|---|
pages:registercrud |
Register Pagina and Section models with CrudGenerator |
pages:createseed |
Generate a seed file from the current pages/sections data |
pages:registermiddleware |
Register package middleware in the application |
License
The MIT License (MIT). See LICENSE.md.
sirgrimorum/pages 适用场景与选型建议
sirgrimorum/pages 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 239 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 04 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cms」 「pages」 「sirgrimorum」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sirgrimorum/pages 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sirgrimorum/pages 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sirgrimorum/pages 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The "View Counter" bundle
GraphQL authentication for your headless Craft CMS applications.
Adjacency List’ed Closure Table database design pattern implementation for Laravel. Includes restore of tree
Set Links with a specific language parameter
Supercharged text field validation.
Integrate with Snipcart.
统计信息
- 总下载量: 239
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-04-06