atelfoto/sluggable
Composer 安装命令:
composer require atelfoto/sluggable
包简介
Sluggable plugin for CakePHP
README 文档
README
1. Requirements
- cakephp 5.x.x
2. Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require atelfoto/sluggable
- or add it in the composer.json
"require": { "atelfoto/sluggable": "1.*" },
- And in a Table in
initialize();add this line:
//src/Model/Table/model.php $this->addBehavior('Sluggable.Sluggable');
3. Configuration
3.1. Model Table
- Field
- Default: name
- The field to slug
$this->addBehavior('Sluggable.Sluggable', [ 'field' => 'your-field' ] );
- Slug
- Default: slug
- The slug field name in your database:
$this->addBehavior('Sluggable.Sluggable', [ 'field' => 'your-field', 'slug' => 'your-slug' ] );
- Replacement
-
Default:
- -
The replacement characters used to replace space:
$this->addBehavior('Sluggable.Sluggable', [ 'replacement' => '_' ]);
-
3.2. Controller
-
To use in a finder:
public function view($value = null) { $query = $this->Models->findBySlug($value)->firstOrFail(); $this->set(compact('query')); }
3.3. Route
-
In the Route
//config/routes $routes->connect( '/the title/:slug', ['controller' => 'YourController', "action" => "view"], [ "_name" => "the title", "pass" => ['slug'], ] );
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-08-17