PHPackages                             hjp1011/yii2-workflow - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. hjp1011/yii2-workflow

ActiveYii2-extension[Framework](/categories/framework)

hjp1011/yii2-workflow
=====================

A simple workflow engine for Yii2

1.0.0(2y ago)0321BSD-3-ClausePHPPHP &gt;=5.4.0

Since May 16Pushed 2y ago1 watchersCompare

[ Source](https://github.com/hjp1011/yii2-workflow)[ Packagist](https://packagist.org/packages/hjp1011/yii2-workflow)[ Docs](https://github.com/hjp1011/yii2-workflow)[ RSS](/packages/hjp1011-yii2-workflow/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (1)

yii2-workflow
=============

[](#yii2-workflow)

[![Latest Stable Version](https://camo.githubusercontent.com/0184090b746857c186cc0190aad68a62d7d7955e1f256c11ff13ff28703dd56f/687474703a2f2f706f7365722e707567782e6f72672f686a70313031312f796969322d776f726b666c6f772f76)](https://packagist.org/packages/hjp1011/yii2-workflow) [![Total Downloads](https://camo.githubusercontent.com/84e15a36f3632c64205b3cf2590359a96f3e7d2e80cd5ae0402ed4a624d29e18/687474703a2f2f706f7365722e707567782e6f72672f686a70313031312f796969322d776f726b666c6f772f646f776e6c6f616473)](https://packagist.org/packages/hjp1011/yii2-workflow) [![Latest Unstable Version](https://camo.githubusercontent.com/dbcb6bd306cd4302a509c11a0600004b3abd0b2ec50f8120297a09b3f429eba4/687474703a2f2f706f7365722e707567782e6f72672f686a70313031312f796969322d776f726b666c6f772f762f756e737461626c65)](https://packagist.org/packages/hjp1011/yii2-workflow) [![License](https://camo.githubusercontent.com/9f20ed35072f85341fcc1c643b03537bf827659d7a15caf1433e4fae3b9b3d0c/687474703a2f2f706f7365722e707567782e6f72672f686a70313031312f796969322d776f726b666c6f772f6c6963656e7365)](https://packagist.org/packages/hjp1011/yii2-workflow) [![PHP Version Require](https://camo.githubusercontent.com/e03c7be4ef05da16d4dfc6edc3a19a42970acbe2da3ef0d1994b0bc4d62d57d2/687474703a2f2f706f7365722e707567782e6f72672f686a70313031312f796969322d776f726b666c6f772f726571756972652f706870)](https://packagist.org/packages/hjp1011/yii2-workflow)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist hjp1011/yii2-workflow "*"

```

or add

```
"hjp1011/yii2-workflow": "*"

```

to the require section of your `composer.json` file.

Quick Start
===========

[](#quick-start)

Configuration
-------------

[](#configuration)

For this "*Quick start Guide*" we will be using **default configuration settings**, but remember that *yii2-workflow* is designed to be highly flexible so to adapt to a lot of execution contexts... well at least that was my goal.

Create A Workflow
-----------------

[](#create-a-workflow)

A workflow is defined as a PHP class that implements the `\hjp1011\workflow\source\file\IWorkflowDefinitionProvider` interface. which declares the *getDefinition()* method. This method must return an array representing the workflow definition.

Let's define a very *simple workflow* that will be used to manage posts in a basic blog system.

[![](guide/docs/images/workflow1.png)](guide/docs/images/workflow1.png)

Here is the PHP class that implements the definition for our workflow :

`@app/models/PostWorkflow.php`

```
namespace app\models;

class PostWorkflow implements \hjp1011\workflow\source\file\IWorkflowDefinitionProvider
{
	public function getDefinition() {
		return [
			'initialStatusId' => 'draft',
			'status' => [
				'draft' => [
					'transition' => ['publish','deleted']
				],
				'publish' => [
					'transition' => ['draft','deleted']
				],
				'deleted' => [
					'transition' => ['draft']
				]
			]
		];
	}
}
```

Attach To The Model
-------------------

[](#attach-to-the-model)

Now let's have a look to our Post model: we store the status of a post in a column named `status` of type STRING(40).

The last step is to associate the workflow definition with posts models. To do so we must declare the *SimpleWorkflowBehavior* behavior in the Post model class and let the default configuration settings do the rest.

`@app/models/Post.php`

```
namespace app\models;
/**
 * @property integer $id
 * @property string $title
 * @property string $body
 * @property string $status column used to store the status of the post
 */
class Post extends \yii\db\ActiveRecord
{
    public function behaviors()
    {
    	return [
			\hjp1011\workflow\base\SimpleWorkflowBehavior::className()
    	];
    }
    // ...
```

That's it ! We are ready to play with *SimpleWorkflowBehavior*.

Use It !
--------

[](#use-it-)

Now that we are all setup, we can use the *SimpleWorkflowBehavior* methods to set/get the status of our posts : the *SimpleWorkflowBehavior* will take care that the post doesn't reach a status where it is not supposed to go to, depending on the workflow definition that we have provided.

```
$post = new Post();
$post->status = 'draft';
$post->save();
echo 'post status is : '. $post->workflowStatus->label;
```

This will print the following message :

```
post status is : Draft

```

If you do the same thing but instead of *draft* set the status to *publish* and try to save it, the following exception is thrown :

```
Not an initial status : PostWorkflow/publish ("PostWorkflow/draft" expected)

```

That's because in your workflow definition the **initial status** is set to *draft* and not *publish*.

Ok, one more example for the fun ! This time we are not going to perform the transition when the Post is saved (like we did in the previous example), but immediately, by invoking the `sendToStatus` method. Our Post is going to try to reach status *publish* passing through *deleted*which is strictly forbidden by the workflow. Will it be successful in this risky attempt to break workflow rules ?

```
$post = new Post();
$post->sendToStatus('draft');
$post->sendToStatus('deleted');
$post->sendToStatus('publish');	// danger zone !
```

Game Over ! There is no transition between *deleted* and *publish*, and that's what *SimpleWorkflow* tries to explain to our fearless post object.

```
Workflow Exception – hjp1011\workflow\base\WorkflowException
No transition found between status PostWorkflow/deleted and PostWorkflow/publish

```

Yes, that's severe, but there was many ways to avoid this exception like for instance by first validating that the transition was possible.

What's Next ?
-------------

[](#whats-next-)

This is just one way of using the *SimpleWorkflowBehavior* but there's much more and hopefully enough to assist you in workflow management inside your Yii2 web app.

You may also be interested in the following projects developed around yii2-workflow :

- [yii2-workflow-view](https://github.com/hjp1011/yii2-workflow-view) : A Widget to display workflows

License
-------

[](#license)

**yii2-workflow** is released under the BSD 3-Clause License. See the bundled `LICENSE.md` for details.

[![Yii2](https://camo.githubusercontent.com/d6b0929173e28cc627430d2519ca1853466a70f37395877eaf4820cb3e1e1909/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506f77657265645f62792d5969695f4672616d65776f726b2d677265656e2e7376673f7374796c653d666c6174)](http://www.yiiframework.com/)

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1092d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3722805f06e7a49dc67f3ff1c7fac9239b9028169f0aa129b56f4ba641a8d14c?d=identicon)[YiiFrame](/maintainers/YiiFrame)

---

Top Contributors

[![hjp1011](https://avatars.githubusercontent.com/u/15049554?v=4)](https://github.com/hjp1011 "hjp1011 (3 commits)")

---

Tags

workflowyii2

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/hjp1011-yii2-workflow/health.svg)

```
[![Health](https://phpackages.com/badges/hjp1011-yii2-workflow/health.svg)](https://phpackages.com/packages/hjp1011-yii2-workflow)
```

###  Alternatives

[raoul2000/yii2-workflow

A simple workflow engine for Yii2

17289.8k32](/packages/raoul2000-yii2-workflow)[yiisoft/yii2-twig

The Twig integration for the Yii framework

1431.9M32](/packages/yiisoft-yii2-twig)[skeeks/cms

SkeekS CMS — control panel and tools based on php framework Yii2

13825.6k47](/packages/skeeks-cms)[cornernote/yii2-workflow-manager

Workflow Manager for Yii2.

3736.1k26](/packages/cornernote-yii2-workflow-manager)[tecnocen/yii2-workflow

Yii 2 Library to configure workflows

136.2k](/packages/tecnocen-yii2-workflow)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
