-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathdoctrine.html.twig
90 lines (76 loc) · 7.15 KB
/
doctrine.html.twig
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
<h4>Skipper & Doctrine ORM</h4>
<p>Symfony comes with Doctrine ORM framework. Doctrine has <a href="http://www.doctrine-project.org" target="_blank" onClick="recordOutboundLink(this, 'Others', 'http://www.doctrine-project.org');return false;">extensive documentation</a>, but you can start using it right away without a need to dive too deep. <a href="http://www.skipper18.com" target="_blank" onClick="recordOutboundLink(this, 'Others', 'http://www.skipper18.com');return false;">Skipper</a> can make your life with Doctrine and other ORM frameworks much easier.</p>
<p>Skipper is a multiplatform tool for modeling ORM in a very comfortable way. You can continuously export your model and even edit exported classes without losing the changes on consequent exports. What’s also great about Skipper is that it can construct a model from an existing project. And it can do so in a very colourful and well-arranged way :-).</p>
<div class="ormd-image"><img src="images/orm/1-main-screen.png" width="876" height="611"/></div>
<p>Start by <a href="http://www.skipper18.com/en/download" target="_blank" onClick="recordOutboundLink(this, 'Others', 'http://www.skipper18.com/en/download');return false;">downloading Skipper</a> and installing on your computer. Skipper works natively on Mac OS X, Windows and Linux.</p>
<ul class="indent">
<li>
<h4>1. Create a new Skipper project</h4>
<p>Pick your project name and select <strong>MVC Framework Symfony2, ORM Framework Doctrine2 and set a Project Path</strong>. Project Path should be the Symfony2 project root.</p>
<div class="ormd-image"><img src="images/orm/2-choose-framework.png" width="590" height="398"/></div>
</li>
<li>
<h4>1a. Import existing project (Optional)</h4>
<p>Insert existing project name and select <strong>MVC Framework Symfony2, ORM Framework Doctrine2 and set a Project Path</strong>. Project Path should be the Symfony2 project root.</p>
<div class="ormd-image"><img src="images/orm/3-import-project.png" width="590" height="398"/></div>
<p>Select all the entities you want to import:</p>
<div class="ormd-image"><img src="images/orm/4-select-files.png" width="590" height="398"/></div>
</li>
<li>
<h4>2. Set export format</h4>
<p>When creating a new project you need to set the export format. Double click on the module title as shown by the red arrow. Module editor will be opened and you can set export format (<strong>Doctrine2PHP for Doctrine2 annotations, Doctrine2XML/Doctrine2YML for XML/YML format</strong>). You should also set relative path, so the class are exported correctly to your project structure.</p>
<div class="ormd-image"><img src="images/orm/5-export-settings.png" width="599" height="364"/></div>
</li>
<li>
<h4>3. Export project</h4>
<p>Press <em>“Export to ORM”</em> and a table summarizing exported changes to the model will be displayed.</p>
<div class="ormd-image"><img src="images/orm/6-export-results.png" width="687" height="441"/></div>
</li>
</ul>
<h3>Working with the model</h3>
<p>Your first model is now exported. Click Export to ORM button whenever you want to update your schema definitions.</p>
<h4>Create new Entities</h4>
<p>Select tool Entity from the top ribbon (or press <em>Ctrl + T</em>) and click in your model to place the new entity. Add required fields. You can navigate with keyboard shortcuts:<p>
<ul>
<li><em>Insert</em>: to add a new field</li>
<li><em>Ctrl+Up arrow</em>: to move field up</li>
<li><em>Ctrl+Down arrow</em>: to move field down</li>
<li><em>Tab</em>: to skip to the next edit value</li>
<li><em>Ctrl+Insert</em>: to insert a field above currently highlighted row</li>
</ul>
<div class="ormd-image"><img src="images/orm/7-edit-entity.png" width="684" height="379"/></div>
<h4>Create new Association</h4>
<p>Select tool Association from the top ribbon (or press Ctrl + R) and select the entities you want to create association between. By filling either one or both aliases you can set the Association as an unidirectional or bidirectional.</p>
<div class="ormd-image"><img src="images/orm/8-association-wizard.png" width="370" height="441"/></div>
<h4>Create new Many-Many Association</h4>
<p>Select tool ManyToMany from the top ribbon (or press Ctrl + M) and select the entities you want to create association between. Again you need to fill aliases and additionally also the MN Entity name. If you don’t want to type it manually, you can use the naming tool (red arrow) which follows the usual naming conventions.</p>
<div class="ormd-image"><img src="images/orm/9-many-to-many-wizard.png" width="384" height="430"/></div>
<h4>Set Doctrine ORM properties</h4>
<p>You can set ORM properties using the property window in the lower bottom corner of Skipper. Property window shows you available properties based on the object type (Entity/Relation/Field).</p>
<div class="ormd-image"><img src="images/orm/10-property-editor.png" width="257" height="430"/></div>
<h4>Generate doctrine schema</h4>
<p>If you have selected XML or YML format you need to generate the PHP classes <strong>generate:doctrine:entities [bundleNamespace]</strong>. This will automatically create all entity and repository classes for us. Easy, isn’t it? If you have been exporting to PHP annotations you’re ready to go.</p>
<h4>Wide possibilities for customization</h4>
<p>Another great thing about Skipper is a wide range of areas where it is possible to customize the behaviour of the application. For example you can configure list of external commands and executed it directly from the app:</p>
<div class="ormd-image"><img src="images/orm/11-external-tools.png" width="726" height="413"/></div>
<p>Also you can extend shipped ORM properties with your own ones, you can add new datatypes, structures, etc. These configurations can be shared between all projects or add only to specific one. This topic is nicely described in <a href="http://help.skipper18.com/expert-usage/customization/configuration-files" target="_blank" onClick="recordOutboundLink(this, 'Others', 'http://help.skipper18.com/expert-usage/customization/configuration-files');return false;"> Skipper documentation</a>.
<!-- Skipper code end -->
<h4>Persisting object into the database</h4>
<p>Now that you have a mapped Product entity and corresponding product table, you're ready to persist
data to the database. From inside a controller, this is pretty easy. Add the following method to the
DefaultController of the bundle:</p>
<pre><code>// src/Acme/StoreBundle/Controller/DefaultController.php
use Acme\StoreBundle\Entity\Product;
use Symfony\Component\HttpFoundation\Response;
public function createAction()
{
$product = new Product();
$product->setName('A Foo Bar');
$product->setPrice('19.99');
$product->setDescription('Lorem ipsum dolor');
$em = $this->getDoctrine()->getManager();
$em->persist($product); //marks object to be saved in the next transaction.
$em->flush(); //performs all saves and transactions.
return new Response('Created product id '.$product->getId());
}
</code></pre>