Closed juancrobles closed 8 years ago
hi @juancrobles
... and thanks for your contribution.
The use case you're facing should already be handled by yii2-workflow as it is a common case to load the worlfow from another location than the default app\models
namespace.
To load the workflow from a custom namespace you have to declare and initialize the workflow source component (i.e. without relying on the default initialization settings). This is described in the documentation as the standard way.
$config = [
'components' => [
'workflowSource' => [
'class' => 'raoul2000\workflow\source\file\WorkflowFileSource',
'definitionLoader' => [
'class' => 'raoul2000\workflow\source\file\PhpClassLoader',
'namespace' => '@app/models/workflows'
]
],
Another option is to make use of a special alias : @workflowDefinitionNamespace ... in the documentation this is called the magic alias.
Yii::setAlias('@workflowDefinitionNamespace','app\\modules\\workflow\\models');
Check the PHP Class Loader chapter in the doc.
Your PR introduces a dependency between the SimpleWorkflowBehavior and the underlying workflowSource component, between the id of your workflow and the way it is stored. For instance, today my workflow is defined as a PHP class, but maybe tomorrow I want to store it in DB and in this case, having a workflow Id equals to app\modules\workflow\models\AwesomeWorkflow
is not appropriate.
Try to use the standard or the magic alias way and hopefully it will reply to your requirements with minimal effort.
:sunglasses:
Hi, I was testing your extension when I ran into a problem, your extension only allows me to have defined the workflow in "app\models", but my setup requires to locate the definition elsewhere, so I made a couple of changes, to allow to define the right place where my workflow is located; this allow me to have a library of workflows and access them in any place... of course if no declaration is placed the behavior is unchanged
expample of declaration:
cheers
P.S. great work with this extension