-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME
116 lines (86 loc) · 3.73 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
sfEntityAttributeValuePlugin
=============================
The `sfEntityAttributeValuePlugin` is a symfony plugin that allows use of the [Entity-Attribute-Value](http://en.wikipedia.org/wiki/Entity-attribute-value_model)
data-model as a doctrine behavior.
This plugin provides a way to easily create dynamic fields with [jQuery Form Builder Plugin](http://www.botsko.net/blog/2009/04/jquery-form-builder-plugin/)
and bind then to a specific object (DB line) of your model. It also allow you
to fill in these fields from other models that have a ManyToOne relation with
the first one. And finally, these stored EAV can be exploited in edit/read mode.
Installation
------------
* Install the plugin
$ symfony plugin:install sfEntityAttributeValuePlugin
* Activate the plugin in your project configuration file (in config/ProjectConfiguration.class.php).
class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
//...
$this->enablePlugins('sfEntityAttributeValuePlugin');
}
}
* Apply the EAV behavior to your model in your schema file `config/doctrine/schema.yml` , ie:
Assume that we want to bind dynamic fields to each object of a model called "ParentModel" and then
insert data in these fields from a 'ChildModel' who is related as ManyToOne to the "ParentModel", the schema
will contain config like this:
ParentModel:
actAs:
EavBehavior:
mode: create
columns:
...
ChildModel:
actAs:
EavBehavior:
mode: insert
parent_resource: ParentModel
columns:
parent_model_id: { type: integer }
...
relations:
ParentModel: { local: parent_model_id, foreign: id }
* Build Eav models and create tables :
$ symfony doctrine:build --all
alternatively you could build the models, the sql, then run the sql manually
* Build (or update) the global resource file to affect unique id for all your models
$ symfony eav:init-config
Important note: this task will create/update the file resources.yml that hold the
models ids, do not change manually this files, this may damage your EAV structure!
* Activate the "eav" module in the settings.yml:
all:
.settings:
enabled_modules: [ default, eav ]
* publish assets
$ symfony plugin:publish-assets
* Clear your cache
$ symfony cc
* Add the sfWidgetFormEav as a widgetSchema in all forms that have the EavBehavior. The sfEntityAttributeValuePlugin
is enough smart to render the widget in create or insert mode.
# lib/form/doctrine/ParentModelForm.php
class ParentModelForm extends BaseParentModelForm
{
public function configure()
{
$this->widgetSchema['eav'] = new sfWidgetFormEav($this);
}
}
# lib/form/doctrine/ChildModelForm.php
class ChildModelForm extends BaseChildModelForm
{
public function configure()
{
$this->widgetSchema['eav'] = new sfWidgetFormEav($this);
}
}
* Add the widget "eav" in the form partial
# _form.php
echo $form['eav']-> renderRow();
(future improvements)
Ajax eav child binder: when editing a child entity, eav structure will be updated via Ajax.
----------------------
Smart EAV tables cleaner: to clean obsolete data from eav tables.
-------------------------
Required Field support
----------------------
Sortable EAV
------------