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

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

raoul2000/yii2-workflow
=======================

A simple workflow engine for Yii2

1.2.0(7y ago)17289.8k↓40.9%48[1 issues](https://github.com/raoul2000/yii2-workflow/issues)20BSD-3-ClausePHPPHP &gt;=5.4.0

Since Apr 20Pushed 7y ago20 watchersCompare

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

READMEChangelog (10)Dependencies (7)Versions (15)Used By (20)

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

[](#yii2-workflow)

[![Build](https://camo.githubusercontent.com/592e1663667c26366e5dd1b20ba8d47cfa298af10ca28eee5cbf0eda5c5dd546/68747470733a2f2f7472617669732d63692e6f72672f72616f756c323030302f796969322d776f726b666c6f772e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/raoul2000/yii2-workflow)[![Latest Stable Version](https://camo.githubusercontent.com/3c96291ccc0e46aa8edecc1a56af57398c7d6131bb768f90786a22b4562fa316/68747470733a2f2f706f7365722e707567782e6f72672f72616f756c323030302f796969322d776f726b666c6f772f762f737461626c65)](https://packagist.org/packages/raoul2000/yii2-workflow)[![Total Downloads](https://camo.githubusercontent.com/05e7a26f92ec1c86b20d71496b9617f0aea94e4aef6eef0753ef6b8f7ecadb0a/68747470733a2f2f706f7365722e707567782e6f72672f72616f756c323030302f796969322d776f726b666c6f772f646f776e6c6f616473)](https://packagist.org/packages/raoul2000/yii2-workflow)[![License](https://camo.githubusercontent.com/68caded038157f70b50832fca329df9d46f01a091038a2609809d2b51c47e46e/68747470733a2f2f706f7365722e707567782e6f72672f72616f756c323030302f796969322d776f726b666c6f772f6c6963656e7365)](https://packagist.org/packages/raoul2000/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 raoul2000/yii2-workflow "*"

```

or add

```
"raoul2000/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 `\raoul2000\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 \raoul2000\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 [
			\raoul2000\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 – raoul2000\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://raoul2000.github.io/yii2-workflow/)
- [yii2-workflow Class Reference](http://raoul2000.github.io/yii2-workflow/class-ref/)
- [Demo](http://raoul2000.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/raoul2000/yii2-workflow-view) : A Widget to display workflows ([demo](http://raoul2000.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/raoul2000/yii2-wizflow) : a proof of concept that mixes the Wizard UI pattern with workflow ([Demo](http://raoul2000.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

45

—

FairBetter than 93% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community36

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 90.4% 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

Every ~95 days

Recently: every ~225 days

Total

13

Last Release

2902d ago

Major Versions

0.0.20 → 1.0.02015-12-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/ec7e087ebb28d42d781766dce67eb6d8911a11a5e3dd7e793800f506d17f0a00?d=identicon)[raoul2000](/maintainers/raoul2000)

---

Top Contributors

[![raoul2000](https://avatars.githubusercontent.com/u/1474310?v=4)](https://github.com/raoul2000 "raoul2000 (188 commits)")[![cornernote](https://avatars.githubusercontent.com/u/51875?v=4)](https://github.com/cornernote "cornernote (9 commits)")[![pappfer](https://avatars.githubusercontent.com/u/738623?v=4)](https://github.com/pappfer "pappfer (5 commits)")[![marcoadasilvaa](https://avatars.githubusercontent.com/u/4205973?v=4)](https://github.com/marcoadasilvaa "marcoadasilvaa (2 commits)")[![Faryshta](https://avatars.githubusercontent.com/u/2029247?v=4)](https://github.com/Faryshta "Faryshta (2 commits)")[![michelezucchini](https://avatars.githubusercontent.com/u/13572596?v=4)](https://github.com/michelezucchini "michelezucchini (1 commits)")[![ChanceBioIT](https://avatars.githubusercontent.com/u/8458784?v=4)](https://github.com/ChanceBioIT "ChanceBioIT (1 commits)")

---

Tags

phpstatustransitionworkflowyii2yii2-extensionworkflowyii2

###  Code Quality

TestsCodeception

### Embed Badge

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

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

###  Alternatives

[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)
