Development

/doc/tags/RELEASE_1_0_5/refcard/admin_refcard.html

You must first sign up to be able to contribute.

root/doc/tags/RELEASE_1_0_5/refcard/admin_refcard.html

Revision 1628, 10.9 kB (checked in by francois, 2 years ago)

updated admin ref card for form validation syntax

Line 
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2000/REC-xhtml1-200000126/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3 <head>
4 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
5 <title>symfony admin generator reference card</title>
6 <link rel="stylesheet" type="text/css" href="refcard.css" />
7 <style>
8 body
9 {
10   width: 1275px;
11 }
12
13 pre
14 {
15   font-size: 10px;
16 }
17 .subcol
18 {
19   width: 420px;
20 }
21 h1
22 {
23   background-color: #673A00;
24 }
25 .subcol h2
26 {
27   background-color: #747A89;
28 }
29 .subcol h3
30 {
31   background-color: #C6CDDE;
32   color: #000;
33 }
34 body
35 {
36   background-color: #fff;
37 }
38 </style>
39 </head>
40 <body>
41
42 <h1>&raquo;&nbsp;symfony admin generator reference card 1.0&nbsp;&laquo;</h1>
43
44
45 <div class="col">
46 <!-- column start -->
47
48
49 <div class="subcol">
50 <h2>Command Line</h2>
51 <div class="content">
52
53   <h3>Options in this order: &lt;APP&gt; &lt;MODULE&gt; &lt;OBJECT&gt;</h3>
54   <span class="method">$ symfony propel-init-admin backend post Post</span><br />
55   <span class="method">$ symfony propel-init-admin backend comment Comment</span><br />
56
57 </div>
58 </div>
59
60
61 <div class="subcol">
62 <h2>Generated code (can be overridden per module)</h2>
63 <div class="content">
64  
65   accessible in cache/backend/&lt;ENV&gt;/modules/&lt;MODULE&gt;
66   <div style="float:left;width:59%;margin-right:2%;">
67     <h3>Actions</h3>
68     <span class="method">create -> edit</span><br />
69     <span class="method">delete</span><br />
70     <span class="method">edit</span><br />
71     <span class="method">index -> list</span><br />
72     <span class="method">list</span><br />
73     <span class="method">save -> edit</span><br />
74     <h3>Methods</h3>
75     <span class="method">public handleErrorEdit()</span><br />
76     <span class="method">protected save&lt;OBJECT&gt;()</span><br />
77     <span class="method">protected delete&lt;OBJECT&gt;()</span><br />
78     <span class="method">protected update&lt;OBJECT&gt;FromRequest()</span><br />
79     <span class="method">protected get&lt;OBJECT&gt;OrCreate()</span><br />
80     <span class="method">protected processFilters()</span><br />
81     <span class="method">protected processSort()</span><br />
82     <span class="method">protected addFiltersCriteria()</span><br />
83     <span class="method">protected addSortCriteria()</span><br />
84   </div>
85   <div style="float:left;width:39%">
86     <h3>Templates</h3>
87     <span class="method">_edit_actions.php   </span><br />                               
88     <span class="method">_edit_footer.php    </span><br />                             
89     <span class="method">_edit_header.php    </span><br />                             
90     <span class="method">_filters.php        </span><br />                             
91     <span class="method">_list_actions.php   </span><br />                             
92     <span class="method">_list_footer.php    </span><br />                             
93     <span class="method">_list_header.php    </span><br />                             
94     <span class="method">_list_td_actions.php</span><br />                             
95     <span class="method">_list_td_stacked.php</span><br />                             
96     <span class="method">_list_td_tabular.php</span><br />                             
97     <span class="method">_list_th_tabular.php</span><br />                             
98     <span class="method">_list_th_stacked.php</span><br />                             
99     <span class="method">editSuccess.php     </span><br />                             
100     <span class="method">listSuccess.php     </span><br />
101   </div>
102   <br style="clear:both" />
103    
104 </div>
105 </div>
106
107 <div class="subcol">
108 <h2>generator.yml</h2>
109 <div class="content">
110
111 <pre>
112 generator:
113   class:              sfPropelAdminGenerator
114   param:
115     model_class:      Post
116     theme:            default
117
118     fields:
119       author_id:      { name: Post author }
120    
121     list:
122       title:          symfony blog posts
123       display:        [title, author_id, category_id]
124       fields:
125         published_on: { params: date_format='dd/MM/yy' }
126       layout:         stacked
127       params: |
128         %%is_published%%&lt;strong&gt;%%=title%%&lt;/strong&gt;&lt;br /&gt;
129         &lt;em&gt;by %%author%% in %%category%%
130         (%%published_on%%)&lt;/em&gt;&lt;p&gt;%%content_summary%%&lt;/p&gt;
131       filters:        [title, category_id, is_published]
132       max_per_page:   2
133      
134     edit:
135       title:          Editing post "%%title%%"
136       display:
137         "Post":       [title, category_id, content]
138         "Workflow":   [author_id, is_published, created_on]
139       fields:
140         category_id:  { params: disabled=true }
141         content:
142           params:     rich=true tinymce_options=height:150
143         author_id:
144           params:     size=5 include_custom=Choose an author
145         is_published: { credentials: [[admin, superdamin]] }
146         created_on:   { type: plain, params: date_format='dd/MM' }
147 </pre>
148
149 </div>
150 </div>
151
152 <div class="subcol">
153 <h2>Validation & Repopulation</h2>
154 <div class="content">
155
156 <div style="float:right;">apps/backend/modules/post/validate/edit.yml</div>
157 <pre>
158 methods:
159     post:
160       - "post{title}"
161       - "post{body}"
162 names:
163   post{title}:
164     required:     Yes
165     required_msg: You must provide a title
166   post{body}:
167     required:     No
168     validators:   [antiSpamValidator, MyStringValidator]
169 fillin:
170   activate:       on
171 </pre>
172 </div>
173
174 </div>
175
176 <!-- column end -->
177 </div>
178
179
180 <div class="col">
181 <!-- column start -->
182
183 <div class="subcol">
184 <h2>Presentation</h2>
185 <div class="content">
186 <pre>
187 generator:
188   class:          sfPropelAdminGenerator
189   param:
190     model_class:  Post
191     theme:        mytheme              ## custom theme     
192     css:          admin/mystylesheet   ## custom css
193 </pre>
194 </div>
195 </div>
196
197 <div class="subcol">
198 <h2>Display (ordering and grouping)</h2>
199 <div class="content">
200 <h3>list view</h3>
201 The equal sign (=) selects the field holding the hyperlink to the edit view
202 <pre>
203     list:
204       ## tabular layout
205       display: [=title, author_id, created_at]
206      
207       ## stacked layout
208       layout:  stacked
209       display: [title, author_id, created_at]
210       params: |
211         &lt;strong&gt;%%=title%%&lt;/strong&gt;
212         by %%author%% (issued on %%created_at%%)
213 </pre>
214 Stacked layout uses display setting for the column headers (and sorting)
215
216 <h3>edit view</h3>
217 <pre>
218     edit:
219       ## ungrouped
220       display:    [title, author_id, created_at]
221      
222       ## grouped
223       display:
224         "NONE":   [id]
225         "Group1": [title, body]
226         "Group2": [created_at]
227 </pre>
228 Groups with label <span class="method">"NONE"</span> have no label
229
230 </div>
231 </div>
232
233 <div class="subcol">
234 <h2>Additional list settings</h2>
235 <div class="content">
236 <h3>Filters</h3>
237 <pre>
238   filters:
239     - title         ## text filter, accepts * as wildcard
240     - author        ## foreign_key filter, displays select
241     - created_at    ## date filter from... to...
242     - is_admin      ## boolean filter, yes/no/yes or no
243 </pre>
244 <h3>Pagination</h3>
245 <pre>
246   max_per_page: 10  ## maximum number of records per page
247 </pre>
248 <h3>Sorting</h3>
249 <pre>
250   sort: created_at  ## sort column (ascending order by default)
251   sort: [created_at, desc]  ## desc sort order
252 </pre>
253 </div>
254 </div>
255
256 <div class="subcol">
257 <h2>Interactions</h2>
258 <div class="content">
259
260 <h3>Default actions</h3>
261 <pre>
262 list:
263   object_actions:
264     _edit:    -
265     _delete:  -         
266   actions:
267     _create:  -
268 edit:
269   actions:       
270     _list:         -
271     _save:         -
272     _save_and_add: -
273     _delete:       -
274 </pre>
275 <h3>Parameters</h3>
276 <pre>
277   actions:
278     my_action:
279       name:        Add a comment
280       action:      addComment
281       icon:        backend/addcomment.png
282       only_for:    edit        ## Restrict to edit or create
283       params:      class=foobar confirm=Are you sure?
284       credentials: [[admin, superuser], owner]
285 </pre>
286
287 </div>
288 </div>
289
290 <!-- column end -->
291 </div>
292
293
294 <div class="col">
295 <!-- column start -->
296
297 <div class="subcol">
298 <h2>Fields</h2>
299 <div class="content">
300 <h3>Parameters</h3>
301 <pre>
302 fields:
303   my_field:
304     name:        ## Field label/header
305     help:        ## Tooltip, displays when requested
306     type:        ## for edit view only, see below
307     credentials: ## Classic AND/OR credentials array
308     params:      ## html options, depending on the tag
309 </pre>
310 <h3>Cascade</h3>
311 First declaration covers the whole module<br />
312 can be specialized for each view
313 <pre>
314 fields:
315   author:   { name: Author }
316 list:
317   fields:
318     author: { help: This is the author of the comment }
319 edit:
320   fields:
321     author: { name: Author of the comment }
322 </pre>
323 <h3>Input types</h3>
324 <pre>
325 fields:
326   my_field:
327     type:
328       plain          ## No input
329       input_tag      ## Default for text, numeric
330       textarea_tag   ## Default for longvarchar
331       input_date_tag ## Default for date and timestamp
332       select_tag     ## Default for foreign keys
333                      ## And for booleans
334       checkbox_tag
335       radiobutton_tag
336       admin_input_upload_tag
337 </pre>
338
339 <h3>Usual params</h3>
340 <pre>
341 fields:
342   my_field:
343     params:
344       disabled=true             
345       date_format='MM/dd/yy' ## For dates
346       include_blank=true     ## For select tags
347       include_custom=Choose from the list
348       size=45x5              ## For textareas
349       rich=true
350       tinymce_options=height:150
351 </pre>
352
353 </div>
354 </div>
355
356 <div class="subcol">
357 <h2>Special fields</h2>
358 <div class="content">
359
360 <h3>Custom fields</h3>
361 Fields not defined in the <span class="method">schema.xml</span> but for which a custom getter and/or setter were defined in the model.
362 <div style="float:right;">modules/post/config/generator.yml</div>
363 <pre>
364 list:
365   display:        [nb_comments]
366   fields:
367     nb_comments:  { name: Number of comments }
368 </pre>
369 <br />
370 <div style="float:right;">apps/lib/model/Post.php</div>
371 <pre>
372 public function getNbComments()
373 {
374   return count($this->getComments());
375 }
376 </pre>
377
378 <h3>Partial fields</h3>
379 Fields declared with a <span class="method">_</span> prefix in the <span class="method">display:</span> key refer to a partial in the module's <span class="method">template/</span> dir.<br />
380 Use the name without prefix under the <span class="method">fields:</span> key.
381 <div style="float:right;">modules/comment/config/generator.yml</div>
382 <pre>
383 list:
384   display:        [_post_link]
385   fields:
386     post_link:    { name: Related Post }
387 </pre>
388 <br />
389 <div style="float:right;">modules/comment/templates/_post_link.php</div>
390 <pre>
391 &lt;php echo link_to(
392   $comment->getPost()->getTitle(),
393   'post/edit?id='.$comment->getPostId()
394 ) ?&gt;
395 </pre>
396 Partials gain automatic access to the current object $&lt;object&gt;.
397 </div>
398 </div>
399
400 <!-- column end -->
401 </div>
402
403 <div style="clear: both"></div>
404
405 <div class="footnote"></div>
406
407 </body>
408 </html>
Note: See TracBrowser for help on using the browser.