romano83/cakephp3-draft
最新稳定版本:v1.0
Composer 安装命令:
composer require romano83/cakephp3-draft
包简介
This Draft plugin give you the ability to quickly create draft system for your models
README 文档
README
This Draft plugin give you the ability to quickly create draft system for your models.
This plugin is the Grafikart's Cakephp-Draft plugin for CakePHP 3.*
Installation
Requirements
Steps to install
- Run :
composer require romano83/cakephp3-draft:1.*
How to use
In your config\bootstrap.php file, add this line
Plugin::load('Romano83/cakephp3-draft');
Or
Plugin::loadAll();
The plugin is now loaded and you can add the DraftBehavior in your tables:
<?php namespace MyApp\Model\Table; use Cake\ORM\Table; class PostsTable extends Table { public function initialize(array $config) { $this->addBehavior('Romano83/Cakephp3Draft.Draft'); } }
By default, the plugin use an "online" field to set the state of a content.
- online = -1 when the content is a draft
- online = 0 when the content is offline
- online = 1 when content is online
Customization
If you want to use custom fields, you can override default behavior configuration :
<?php namespace MyApp\Model\Table; use Cake\ORM\Table; class PostsTable extends Table { public function initialize(array $config) { $this->addBehavior( 'Romano83/Cakephp3Draft.Draft', [ 'conditions' => [ 'draft' => 1 ] ] ); } }
For instance, this configuration will use a "draft" field (set to 1), to create Draft.
Methods
With the plugin attached, the model will have new method, getDraftId(Table $table, array $conditions = []) witch return draft ID.
The first parameter is a \Cake\ORM\Table instance and the second one is an optional array.
How to implement this method
Here, is an example of how to use this method in your PostsController:
public function add(){ $post = $this->Posts->newEntity(); if($this->request->is(['post', 'put'])){ // Do your stuff here... }else{ $post->id = $this->Posts->getDraftId($this->Posts); // get the last draft Id or create new one if needed } } // OR public function add(){ $post = $this->Posts->newEntity(); if($this->request->is(['post', 'put'])){ // Do your stuff here... }else{ $post->id = $this->Posts->getDraftId($this->Posts, ['user_id' => 2]); // Get a draft Id for a content belonging to user 2 (or create a new one) } }
If you want to clean your table from drafts, you can implement this method:
$this->Posts->cleanDrafts($this->Posts);
How to contribute
- Create a ticket in GitHub, if you have found a bug.
- Create a new branch if you want do a PR.
- Your code must follow the Coding Standard of CakePHP.
- You must add testcases if needed.
Special thanks
- Grafikart for the first version of this plugin !
romano83/cakephp3-draft 适用场景与选型建议
romano83/cakephp3-draft 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 181 次下载、GitHub Stars 达 3, 最近一次更新时间为 2015 年 08 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「model」 「Behavior」 「draft」 「cakephp3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 romano83/cakephp3-draft 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 romano83/cakephp3-draft 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 romano83/cakephp3-draft 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A CakePHP plugin to provide easy access to zumba/swivel
This is a set of Yii2 behaviors extensions
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Draft, publish and revise Laravel Eloquent Models
Interfaces for web resource models and services to retrieve and create them
CakePHP plugin for approval workflow - users propose changes, admins approve or reject before publishing
统计信息
- 总下载量: 181
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-01