定制 romano83/cakephp3-draft 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

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

Build Status Coverage Status Latest Stable Version License

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 !

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固