PHPackages                             jinowom/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. jinowom/yii2-workflow

ActiveYii2-extension

jinowom/yii2-workflow
=====================

A simple workflow engine for Yii2

v1.2.0(3y ago)0202BSD-3-ClausePHPPHP &gt;=5.4.0

Since Oct 30Pushed 3y agoCompare

[ Source](https://github.com/jinowom/yii2-workflow)[ Packagist](https://packagist.org/packages/jinowom/yii2-workflow)[ Docs](http://jinowom.github.io/yii2-workflow/guide-README.html)[ RSS](/packages/jinowom-yii2-workflow/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (3)Used By (2)

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

[](#yii2-workflow)

[![Build](https://camo.githubusercontent.com/476f44ad6f8d7113c5a9c47d72a7d0b50fe43a2b2d5d62adb0e8166e094f1af8/68747470733a2f2f7472617669732d63692e6f72672f6a696e6f776f6d2f796969322d776f726b666c6f772e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jinowom/yii2-workflow)[![Latest Stable Version](https://camo.githubusercontent.com/df2d5cfd212afe757f3343714f9a71f492962ddc247de6ea98178c0a0c592caa/68747470733a2f2f706f7365722e707567782e6f72672f6a696e6f776f6d2f796969322d776f726b666c6f772f762f737461626c65)](https://packagist.org/packages/jinowom/yii2-workflow)[![Total Downloads](https://camo.githubusercontent.com/8ab593a47503a4abb668b4e276b6793d95d4ce0bf53588ec39e9a86d9e7ab8e7/68747470733a2f2f706f7365722e707567782e6f72672f6a696e6f776f6d2f796969322d776f726b666c6f772f646f776e6c6f616473)](https://packagist.org/packages/jinowom/yii2-workflow)[![License](https://camo.githubusercontent.com/bba2ffb0cd079c1c4710475e3dab57681234374fb0911d6a3ec4db4d691180f4/68747470733a2f2f706f7365722e707567782e6f72672f6a696e6f776f6d2f796969322d776f726b666c6f772f6c6963656e7365)](https://packagist.org/packages/jinowom/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 jinowom/yii2-workflow "*"

```

or add

```
"jinowom/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 `\jinowom\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 \jinowom\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 [
			\jinowom\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 – jinowom\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 will find additional information there :

- [yii2-workflow Usage Guide](http://jinowom.github.io/yii2-workflow/)
- [yii2-workflow Class Reference](http://jinowom.github.io/yii2-workflow/class-ref/)
- [Demo](http://jinowom.ass-team.fr/index.php?r=workflow/status-history/update) : a simple example based on the *Post* use case.

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

- [yii2-workflow-view](https://github.com/jinowom/yii2-workflow-view) : A Widget to display workflows ([demo](http://jinowom.ass-team.fr/index.php?r=workflow/status-history/update))
- [yii2-workflow-manager](https://github.com/cornernote/yii2-workflow-manager) : A Module to manage workflows
- [yii2-wizflow](https://github.com/jinowom/yii2-wizflow) : a proof of concept that mixes the Wizard UI pattern with workflow ([Demo](http://jinowom.ass-team.fr/index.php?r=workflow/wizflow/init))
- ..and more to come

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

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 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

1289d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b263a1a85f4ed56baa2458ee30abe2a215f2acec53715c57c3bacc91693de4a?d=identicon)[charleslee](/maintainers/charleslee)

---

Top Contributors

[![jinostart](https://avatars.githubusercontent.com/u/41822778?v=4)](https://github.com/jinostart "jinostart (2 commits)")

---

Tags

workflowyii2

###  Code Quality

TestsCodeception

### Embed Badge

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

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

###  Alternatives

[raoul2000/yii2-workflow

A simple workflow engine for Yii2

17289.8k32](/packages/raoul2000-yii2-workflow)[cornernote/yii2-workflow-manager

Workflow Manager for Yii2.

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

A simple widget to display your workflows

1638.8k20](/packages/raoul2000-yii2-workflow-view)

PHPackages © 2026

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