muffin/slug
Composer 安装命令:
composer require muffin/slug
包简介
Slugging support for CakePHP ORM
README 文档
README
Slugging for CakePHP
Installation
Using Composer:
composer require muffin/slug
Load the plugin using the CLI command:
./bin/cake plugin load Muffin/Slug
Usage
To enable slugging add the behavior to your table classes in the
initialize() method.
public function initialize(array $config): void { //etc $this->addBehavior('Muffin/Slug.Slug', [ // Optionally define your custom options here (see Configuration) ]); }
Please note that Slug expects a database column named
slugto function. If you prefer to use another column make sure to specify thefieldconfiguration option.
Searching
If you want to find a record using its slug, a custom finder is provided by the plugin.
// src/Controller/ExamplesController.php $example = $this->Examples->find('slugged', slug: $slug);
Configuration
Slug comes with the following configuration options:
field: name of the field (column) to hold the slug. Defaults toslug.displayField: name of the field(s) to build the slug from. Defaults to the\Cake\ORM\Table::displayField().separator: defaults to-.replacements: hash of characters (or strings) to custom replace before generating the slug.maxLength: maximum length of a slug. Defaults to the field's limit as defined in the schema (when possible). Otherwise, no limit.slugger: class that implements theMuffin\Slug\SlugInterface. Defaults toMuffin\Slug\Slugger\CakeSlugger.unique:: tells if slugs should be unique. Set this to a callable if you want to customize how unique slugs are generated. Defaults totrue.scope: extra conditions used when checking a slug for uniqueness.implementedEvents: events this behavior listens to. Defaults to['Model.buildValidator' => 'buildValidator', 'Model.beforeSave' => 'beforeSave']. By default the behavior adds validation for thedisplayFieldfields to make them required on record creating. If you don't want these auto added validations you can setimplementedEventsto just['Model.beforeSave' => 'beforeSave'].onUpdate: Boolean indicating whether slug should be updated when updating record, defaults tofalse.onDirty: Boolean indicating whether slug should be updated when slug field is dirty (has a preset value custom value), defaults tofalse.
Sluggers
The plugin contains two sluggers:
CakeSlugger
The CakeSlugger uses \Cake\Utility\Text::slug() to generate slugs. In the
behavior config you can set the slugger key as shown below to pass options to
the $options arguments of Text::slug().
'slugger' => [ 'className' => \Muffin\Slug\Slugger\CakeSlugger::class, 'transliteratorId' => '<A valid ICU Transliterator ID here>' ]
ConcurSlugger
The ConcurSlugger uses concur/slugify to generate slugs.
You can use config array similar to the one shown above to pass options to
Cocur\Slugify\Slugify's constructor.
Patches & Features
- Fork
- Mod, fix
- Test - this is important, so it's not unintentionally broken
- Commit - do not mess with license, todo, version, etc. (if you do change any, bump them into commits of their own that I can ignore when I pull)
- Pull request - bonus point for topic branches
To ensure your PRs are considered for upstream, you MUST follow the CakePHP coding standards.
Bugs & Feedback
http://github.com/usemuffin/slug/issues
License
Copyright (c) 2015-Present, Use Muffin and licensed under The MIT License.
muffin/slug 适用场景与选型建议
muffin/slug 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 277.88k 次下载、GitHub Stars 达 37, 最近一次更新时间为 2015 年 04 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「orm」 「cakephp」 「slug」 「muffin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 muffin/slug 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 muffin/slug 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 muffin/slug 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
TitleWithSlugInput - Easy Permalink Slugs for the FilamentPHP Form Builder (PHP / Laravel / Livewire)
Kinikit - PHP Application development framework MVC component
Adds slugify twig extensions to your craft install.
PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2
A library to extend Object capabilities.
统计信息
- 总下载量: 277.88k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 38
- 点击次数: 33
- 依赖项目数: 7
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-15