Deployed c4a26d0 to 5.4 with MkDocs 1.1.2 and mike 0.5.5
[GitHub/WoltLab/woltlab.github.io.git] / latest / php / database-objects / index.html
1
2 <!doctype html>
3 <html lang="en" class="no-js">
4 <head>
5
6 <meta charset="utf-8">
7 <meta name="viewport" content="width=device-width,initial-scale=1">
8
9
10
11
12 <link rel="shortcut icon" href="../../assets/default.favicon.ico">
13 <meta name="generator" content="mkdocs-1.1.2, mkdocs-material-7.0.5">
14
15
16
17 <title>Database Objects - WoltLab Suite Documentation</title>
18
19
20
21 <link rel="stylesheet" href="../../assets/stylesheets/main.77f3fd56.min.css">
22
23
24 <link rel="stylesheet" href="../../assets/stylesheets/palette.7fa14f5b.min.css">
25
26
27
28 <meta name="theme-color" content="#009485">
29
30
31
32
33
34
35
36
37
38 <link rel="stylesheet" href="../../stylesheets/extra.css">
39
40
41
42
43
44 </head>
45
46
47
48
49
50
51
52 <body dir="ltr" data-md-color-scheme="" data-md-color-primary="teal" data-md-color-accent="">
53
54
55
56 <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
57 <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
58 <label class="md-overlay" for="__drawer"></label>
59 <div data-md-component="skip">
60
61
62 <a href="#database-objects" class="md-skip">
63 Skip to content
64 </a>
65
66 </div>
67 <div data-md-component="announce">
68
69 <aside class="md-announce">
70 <div class="md-announce__inner md-grid md-typeset">
71
72 <a href="https://www.woltlab.com">Back to <strong>woltlab.com</strong></a>
73
74 </div>
75 </aside>
76
77 </div>
78
79
80
81 <header class="md-header" data-md-component="header">
82 <nav class="md-header__inner md-grid" aria-label="Header">
83 <a href="../.." title="WoltLab Suite Documentation" class="md-header__button md-logo" aria-label="WoltLab Suite Documentation">
84
85 <img src="../../assets/logo.png" alt="logo">
86
87 </a>
88 <label class="md-header__button md-icon" for="__drawer">
89 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2z"/></svg>
90 </label>
91 <div class="md-header__title" data-md-component="header-title">
92 <div class="md-header__ellipsis">
93 <div class="md-header__topic">
94 <span class="md-ellipsis">
95 WoltLab Suite Documentation
96 </span>
97 </div>
98 <div class="md-header__topic" data-md-component="header-topic">
99 <span class="md-ellipsis">
100
101 Database Objects
102
103 </span>
104 </div>
105 </div>
106 </div>
107 <div class="md-header__options">
108
109 </div>
110
111 <label class="md-header__button md-icon" for="__search">
112 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
113 </label>
114
115 <div class="md-search" data-md-component="search" role="dialog">
116 <label class="md-search__overlay" for="__search"></label>
117 <div class="md-search__inner" role="search">
118 <form class="md-search__form" name="search">
119 <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" data-md-state="active" required>
120 <label class="md-search__icon md-icon" for="__search">
121 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg>
122 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
123 </label>
124 <button type="reset" class="md-search__icon md-icon" aria-label="Clear" tabindex="-1">
125 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/></svg>
126 </button>
127 </form>
128 <div class="md-search__output">
129 <div class="md-search__scrollwrap" data-md-scrollfix>
130 <div class="md-search-result" data-md-component="search-result">
131 <div class="md-search-result__meta">
132 Initializing search
133 </div>
134 <ol class="md-search-result__list"></ol>
135 </div>
136 </div>
137 </div>
138 </div>
139 </div>
140
141
142 </nav>
143 </header>
144
145 <div class="md-container" data-md-component="container">
146
147
148
149
150 <main class="md-main" data-md-component="main">
151 <div class="md-main__inner md-grid">
152
153
154
155 <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
156 <div class="md-sidebar__scrollwrap">
157 <div class="md-sidebar__inner">
158
159
160
161
162
163 <nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
164 <label class="md-nav__title" for="__drawer">
165 <a href="../.." title="WoltLab Suite Documentation" class="md-nav__button md-logo" aria-label="WoltLab Suite Documentation">
166
167 <img src="../../assets/logo.png" alt="logo">
168
169 </a>
170 WoltLab Suite Documentation
171 </label>
172
173 <ul class="md-nav__list" data-md-scrollfix>
174
175
176
177
178
179
180
181
182 <li class="md-nav__item">
183 <a href="../../getting-started/" class="md-nav__link">
184 Getting Started
185 </a>
186 </li>
187
188
189
190
191
192
193
194
195
196
197
198
199
200 <li class="md-nav__item md-nav__item--active md-nav__item--nested">
201
202
203 <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_2" type="checkbox" id="__nav_2" checked>
204
205 <label class="md-nav__link" for="__nav_2">
206 PHP API
207 <span class="md-nav__icon md-icon"></span>
208 </label>
209 <nav class="md-nav" aria-label="PHP API" data-md-level="1">
210 <label class="md-nav__title" for="__nav_2">
211 <span class="md-nav__icon md-icon"></span>
212 PHP API
213 </label>
214 <ul class="md-nav__list" data-md-scrollfix>
215
216
217
218
219
220 <li class="md-nav__item">
221 <a href="../pages/" class="md-nav__link">
222 Pages
223 </a>
224 </li>
225
226
227
228
229
230
231
232
233
234 <li class="md-nav__item md-nav__item--active">
235
236 <input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc">
237
238
239
240
241 <label class="md-nav__link md-nav__link--active" for="__toc">
242 Database Objects
243 <span class="md-nav__icon md-icon"></span>
244 </label>
245
246 <a href="./" class="md-nav__link md-nav__link--active">
247 Database Objects
248 </a>
249
250
251 <nav class="md-nav md-nav--secondary" aria-label="Table of contents">
252
253
254
255
256
257 <label class="md-nav__title" for="__toc">
258 <span class="md-nav__icon md-icon"></span>
259 Table of contents
260 </label>
261 <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
262
263 <li class="md-nav__item">
264 <a href="#databaseobject" class="md-nav__link">
265 DatabaseObject
266 </a>
267
268 </li>
269
270 <li class="md-nav__item">
271 <a href="#databaseobjectdecorator" class="md-nav__link">
272 DatabaseObjectDecorator
273 </a>
274
275 </li>
276
277 <li class="md-nav__item">
278 <a href="#databaseobjecteditor" class="md-nav__link">
279 DatabaseObjectEditor
280 </a>
281
282 <nav class="md-nav" aria-label="DatabaseObjectEditor">
283 <ul class="md-nav__list">
284
285 <li class="md-nav__item">
286 <a href="#create-a-new-row" class="md-nav__link">
287 Create a new row
288 </a>
289
290 </li>
291
292 <li class="md-nav__item">
293 <a href="#updating-an-existing-row" class="md-nav__link">
294 Updating an existing row
295 </a>
296
297 </li>
298
299 <li class="md-nav__item">
300 <a href="#deleting-a-row" class="md-nav__link">
301 Deleting a row
302 </a>
303
304 </li>
305
306 </ul>
307 </nav>
308
309 </li>
310
311 <li class="md-nav__item">
312 <a href="#databaseobjectlist" class="md-nav__link">
313 DatabaseObjectList
314 </a>
315
316 </li>
317
318 <li class="md-nav__item">
319 <a href="#abstractdatabaseobjectaction" class="md-nav__link">
320 AbstractDatabaseObjectAction
321 </a>
322
323 <nav class="md-nav" aria-label="AbstractDatabaseObjectAction">
324 <ul class="md-nav__list">
325
326 <li class="md-nav__item">
327 <a href="#executing-an-action" class="md-nav__link">
328 Executing an Action
329 </a>
330
331 </li>
332
333 <li class="md-nav__item">
334 <a href="#custom-method-with-ajax-support" class="md-nav__link">
335 Custom Method with AJAX Support
336 </a>
337
338 <nav class="md-nav" aria-label="Custom Method with AJAX Support">
339 <ul class="md-nav__list">
340
341 <li class="md-nav__item">
342 <a href="#ajax-validation" class="md-nav__link">
343 AJAX Validation
344 </a>
345
346 </li>
347
348 <li class="md-nav__item">
349 <a href="#create-update-and-delete" class="md-nav__link">
350 create, update and delete
351 </a>
352
353 </li>
354
355 <li class="md-nav__item">
356 <a href="#allow-invokation-by-guests" class="md-nav__link">
357 Allow Invokation by Guests
358 </a>
359
360 </li>
361
362 <li class="md-nav__item">
363 <a href="#acp-access-only" class="md-nav__link">
364 ACP Access Only
365 </a>
366
367 </li>
368
369 </ul>
370 </nav>
371
372 </li>
373
374 </ul>
375 </nav>
376
377 </li>
378
379 </ul>
380
381 </nav>
382
383 </li>
384
385
386
387
388
389
390
391 <li class="md-nav__item">
392 <a href="../database-access/" class="md-nav__link">
393 Database Access
394 </a>
395 </li>
396
397
398
399
400
401
402
403 <li class="md-nav__item">
404 <a href="../exceptions/" class="md-nav__link">
405 Exceptions
406 </a>
407 </li>
408
409
410
411
412
413
414
415
416 <li class="md-nav__item md-nav__item--nested">
417
418
419 <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_2_5" type="checkbox" id="__nav_2_5" >
420
421 <label class="md-nav__link" for="__nav_2_5">
422 API
423 <span class="md-nav__icon md-icon"></span>
424 </label>
425 <nav class="md-nav" aria-label="API" data-md-level="2">
426 <label class="md-nav__title" for="__nav_2_5">
427 <span class="md-nav__icon md-icon"></span>
428 API
429 </label>
430 <ul class="md-nav__list" data-md-scrollfix>
431
432
433
434
435
436 <li class="md-nav__item">
437 <a href="../api/caches/" class="md-nav__link">
438 Caches
439 </a>
440 </li>
441
442
443
444
445
446
447
448 <li class="md-nav__item">
449 <a href="../api/comments/" class="md-nav__link">
450 Comments
451 </a>
452 </li>
453
454
455
456
457
458
459
460 <li class="md-nav__item">
461 <a href="../api/cronjobs/" class="md-nav__link">
462 Cronjobs
463 </a>
464 </li>
465
466
467
468
469
470
471
472 <li class="md-nav__item">
473 <a href="../api/events/" class="md-nav__link">
474 Events
475 </a>
476 </li>
477
478
479
480
481
482
483
484
485 <li class="md-nav__item md-nav__item--nested">
486
487
488 <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_2_5_5" type="checkbox" id="__nav_2_5_5" >
489
490 <label class="md-nav__link" for="__nav_2_5_5">
491 Form Builder
492 <span class="md-nav__icon md-icon"></span>
493 </label>
494 <nav class="md-nav" aria-label="Form Builder" data-md-level="3">
495 <label class="md-nav__title" for="__nav_2_5_5">
496 <span class="md-nav__icon md-icon"></span>
497 Form Builder
498 </label>
499 <ul class="md-nav__list" data-md-scrollfix>
500
501
502
503
504
505 <li class="md-nav__item">
506 <a href="../api/form_builder/overview/" class="md-nav__link">
507 Overview
508 </a>
509 </li>
510
511
512
513
514
515
516
517 <li class="md-nav__item">
518 <a href="../api/form_builder/structure/" class="md-nav__link">
519 Structure
520 </a>
521 </li>
522
523
524
525
526
527
528
529 <li class="md-nav__item">
530 <a href="../api/form_builder/form_fields/" class="md-nav__link">
531 Fields
532 </a>
533 </li>
534
535
536
537
538
539
540
541 <li class="md-nav__item">
542 <a href="../api/form_builder/validation_data/" class="md-nav__link">
543 Validation and Data
544 </a>
545 </li>
546
547
548
549
550
551
552
553 <li class="md-nav__item">
554 <a href="../api/form_builder/dependencies/" class="md-nav__link">
555 Dependencies
556 </a>
557 </li>
558
559
560
561 </ul>
562 </nav>
563 </li>
564
565
566
567
568
569
570
571 <li class="md-nav__item">
572 <a href="../api/package_installation_plugins/" class="md-nav__link">
573 Package Installation Plugins
574 </a>
575 </li>
576
577
578
579
580
581
582
583 <li class="md-nav__item">
584 <a href="../api/user_activity_points/" class="md-nav__link">
585 User Activity Points
586 </a>
587 </li>
588
589
590
591
592
593
594
595 <li class="md-nav__item">
596 <a href="../api/user_notifications/" class="md-nav__link">
597 User Notifications
598 </a>
599 </li>
600
601
602
603
604
605
606
607 <li class="md-nav__item">
608 <a href="../api/sitemaps/" class="md-nav__link">
609 Sitemaps
610 </a>
611 </li>
612
613
614
615 </ul>
616 </nav>
617 </li>
618
619
620
621
622
623
624
625 <li class="md-nav__item">
626 <a href="../code-style/" class="md-nav__link">
627 Code Style
628 </a>
629 </li>
630
631
632
633
634
635
636
637 <li class="md-nav__item">
638 <a href="../apps/" class="md-nav__link">
639 Apps
640 </a>
641 </li>
642
643
644
645
646
647
648
649 <li class="md-nav__item">
650 <a href="../gdpr/" class="md-nav__link">
651 GDPR
652 </a>
653 </li>
654
655
656
657 </ul>
658 </nav>
659 </li>
660
661
662
663
664
665
666
667
668
669
670
671 <li class="md-nav__item md-nav__item--nested">
672
673
674 <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_3" type="checkbox" id="__nav_3" >
675
676 <label class="md-nav__link" for="__nav_3">
677 Languages, Templates & CSS
678 <span class="md-nav__icon md-icon"></span>
679 </label>
680 <nav class="md-nav" aria-label="Languages, Templates & CSS" data-md-level="1">
681 <label class="md-nav__title" for="__nav_3">
682 <span class="md-nav__icon md-icon"></span>
683 Languages, Templates & CSS
684 </label>
685 <ul class="md-nav__list" data-md-scrollfix>
686
687
688
689
690
691 <li class="md-nav__item">
692 <a href="../../view/languages/" class="md-nav__link">
693 Languages
694 </a>
695 </li>
696
697
698
699
700
701
702
703 <li class="md-nav__item">
704 <a href="../../view/templates/" class="md-nav__link">
705 Templates
706 </a>
707 </li>
708
709
710
711
712
713
714
715 <li class="md-nav__item">
716 <a href="../../view/css/" class="md-nav__link">
717 CSS
718 </a>
719 </li>
720
721
722
723 </ul>
724 </nav>
725 </li>
726
727
728
729
730
731
732
733
734
735
736
737 <li class="md-nav__item md-nav__item--nested">
738
739
740 <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_4" type="checkbox" id="__nav_4" >
741
742 <label class="md-nav__link" for="__nav_4">
743 JavaScript API
744 <span class="md-nav__icon md-icon"></span>
745 </label>
746 <nav class="md-nav" aria-label="JavaScript API" data-md-level="1">
747 <label class="md-nav__title" for="__nav_4">
748 <span class="md-nav__icon md-icon"></span>
749 JavaScript API
750 </label>
751 <ul class="md-nav__list" data-md-scrollfix>
752
753
754
755
756
757 <li class="md-nav__item">
758 <a href="../../javascript/general-usage/" class="md-nav__link">
759 General Usage
760 </a>
761 </li>
762
763
764
765
766
767
768
769
770 <li class="md-nav__item md-nav__item--nested">
771
772
773 <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_4_2" type="checkbox" id="__nav_4_2" >
774
775 <label class="md-nav__link" for="__nav_4_2">
776 New API
777 <span class="md-nav__icon md-icon"></span>
778 </label>
779 <nav class="md-nav" aria-label="New API" data-md-level="2">
780 <label class="md-nav__title" for="__nav_4_2">
781 <span class="md-nav__icon md-icon"></span>
782 New API
783 </label>
784 <ul class="md-nav__list" data-md-scrollfix>
785
786
787
788
789
790 <li class="md-nav__item">
791 <a href="../../javascript/new-api_writing-a-module/" class="md-nav__link">
792 Writing a module
793 </a>
794 </li>
795
796
797
798
799
800
801
802 <li class="md-nav__item">
803 <a href="../../javascript/new-api_data-structures/" class="md-nav__link">
804 Data Structures
805 </a>
806 </li>
807
808
809
810
811
812
813
814 <li class="md-nav__item">
815 <a href="../../javascript/new-api_core/" class="md-nav__link">
816 Core Functions
817 </a>
818 </li>
819
820
821
822
823
824
825
826 <li class="md-nav__item">
827 <a href="../../javascript/new-api_dom/" class="md-nav__link">
828 DOM
829 </a>
830 </li>
831
832
833
834
835
836
837
838 <li class="md-nav__item">
839 <a href="../../javascript/new-api_events/" class="md-nav__link">
840 Event Handling
841 </a>
842 </li>
843
844
845
846
847
848
849
850 <li class="md-nav__item">
851 <a href="../../javascript/new-api_ajax/" class="md-nav__link">
852 Ajax
853 </a>
854 </li>
855
856
857
858
859
860
861
862 <li class="md-nav__item">
863 <a href="../../javascript/new-api_dialogs/" class="md-nav__link">
864 Dialogs
865 </a>
866 </li>
867
868
869
870
871
872
873
874 <li class="md-nav__item">
875 <a href="../../javascript/new-api_browser/" class="md-nav__link">
876 Browser and Screen Sizes
877 </a>
878 </li>
879
880
881
882
883
884
885
886 <li class="md-nav__item">
887 <a href="../../javascript/new-api_ui/" class="md-nav__link">
888 User Interface
889 </a>
890 </li>
891
892
893
894 </ul>
895 </nav>
896 </li>
897
898
899
900
901
902
903
904 <li class="md-nav__item">
905 <a href="../../javascript/legacy-api/" class="md-nav__link">
906 Legacy API
907 </a>
908 </li>
909
910
911
912
913
914
915
916 <li class="md-nav__item">
917 <a href="../../javascript/helper-functions/" class="md-nav__link">
918 Helper Functions
919 </a>
920 </li>
921
922
923
924
925
926
927
928 <li class="md-nav__item">
929 <a href="../../javascript/code-snippets/" class="md-nav__link">
930 Code Snippets
931 </a>
932 </li>
933
934
935
936 </ul>
937 </nav>
938 </li>
939
940
941
942
943
944
945
946
947
948
949
950 <li class="md-nav__item md-nav__item--nested">
951
952
953 <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_5" type="checkbox" id="__nav_5" >
954
955 <label class="md-nav__link" for="__nav_5">
956 Package Components
957 <span class="md-nav__icon md-icon"></span>
958 </label>
959 <nav class="md-nav" aria-label="Package Components" data-md-level="1">
960 <label class="md-nav__title" for="__nav_5">
961 <span class="md-nav__icon md-icon"></span>
962 Package Components
963 </label>
964 <ul class="md-nav__list" data-md-scrollfix>
965
966
967
968
969
970 <li class="md-nav__item">
971 <a href="../../package/package-xml/" class="md-nav__link">
972 package.xml
973 </a>
974 </li>
975
976
977
978
979
980
981
982
983 <li class="md-nav__item md-nav__item--nested">
984
985
986 <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_5_2" type="checkbox" id="__nav_5_2" >
987
988 <label class="md-nav__link" for="__nav_5_2">
989 PIPs
990 <span class="md-nav__icon md-icon"></span>
991 </label>
992 <nav class="md-nav" aria-label="PIPs" data-md-level="2">
993 <label class="md-nav__title" for="__nav_5_2">
994 <span class="md-nav__icon md-icon"></span>
995 PIPs
996 </label>
997 <ul class="md-nav__list" data-md-scrollfix>
998
999
1000
1001
1002
1003 <li class="md-nav__item">
1004 <a href="../../package/pip/" class="md-nav__link">
1005 Overview
1006 </a>
1007 </li>
1008
1009
1010
1011
1012
1013
1014
1015 <li class="md-nav__item">
1016 <a href="../../package/pip/acl-option/" class="md-nav__link">
1017 aclOption
1018 </a>
1019 </li>
1020
1021
1022
1023
1024
1025
1026
1027 <li class="md-nav__item">
1028 <a href="../../package/pip/acp-menu/" class="md-nav__link">
1029 acpMenu
1030 </a>
1031 </li>
1032
1033
1034
1035
1036
1037
1038
1039 <li class="md-nav__item">
1040 <a href="../../package/pip/acp-search-provider/" class="md-nav__link">
1041 acpSearchProvider
1042 </a>
1043 </li>
1044
1045
1046
1047
1048
1049
1050
1051 <li class="md-nav__item">
1052 <a href="../../package/pip/acp-template/" class="md-nav__link">
1053 acpTemplate
1054 </a>
1055 </li>
1056
1057
1058
1059
1060
1061
1062
1063 <li class="md-nav__item">
1064 <a href="../../package/pip/bbcode/" class="md-nav__link">
1065 bbcode
1066 </a>
1067 </li>
1068
1069
1070
1071
1072
1073
1074
1075 <li class="md-nav__item">
1076 <a href="../../package/pip/box/" class="md-nav__link">
1077 box
1078 </a>
1079 </li>
1080
1081
1082
1083
1084
1085
1086
1087 <li class="md-nav__item">
1088 <a href="../../package/pip/clipboard-action/" class="md-nav__link">
1089 clipboardAction
1090 </a>
1091 </li>
1092
1093
1094
1095
1096
1097
1098
1099 <li class="md-nav__item">
1100 <a href="../../package/pip/core-object/" class="md-nav__link">
1101 coreObject
1102 </a>
1103 </li>
1104
1105
1106
1107
1108
1109
1110
1111 <li class="md-nav__item">
1112 <a href="../../package/pip/cronjob/" class="md-nav__link">
1113 cronjob
1114 </a>
1115 </li>
1116
1117
1118
1119
1120
1121
1122
1123 <li class="md-nav__item">
1124 <a href="../../package/pip/event-listener/" class="md-nav__link">
1125 eventListener
1126 </a>
1127 </li>
1128
1129
1130
1131
1132
1133
1134
1135 <li class="md-nav__item">
1136 <a href="../../package/pip/file/" class="md-nav__link">
1137 file
1138 </a>
1139 </li>
1140
1141
1142
1143
1144
1145
1146
1147 <li class="md-nav__item">
1148 <a href="../../package/pip/language/" class="md-nav__link">
1149 language
1150 </a>
1151 </li>
1152
1153
1154
1155
1156
1157
1158
1159 <li class="md-nav__item">
1160 <a href="../../package/pip/media-provider/" class="md-nav__link">
1161 mediaProvider
1162 </a>
1163 </li>
1164
1165
1166
1167
1168
1169
1170
1171 <li class="md-nav__item">
1172 <a href="../../package/pip/menu/" class="md-nav__link">
1173 menu
1174 </a>
1175 </li>
1176
1177
1178
1179
1180
1181
1182
1183 <li class="md-nav__item">
1184 <a href="../../package/pip/menu-item/" class="md-nav__link">
1185 menuItem
1186 </a>
1187 </li>
1188
1189
1190
1191
1192
1193
1194
1195 <li class="md-nav__item">
1196 <a href="../../package/pip/object-type/" class="md-nav__link">
1197 objectType
1198 </a>
1199 </li>
1200
1201
1202
1203
1204
1205
1206
1207 <li class="md-nav__item">
1208 <a href="../../package/pip/object-type-definition/" class="md-nav__link">
1209 objectTypeDefinition
1210 </a>
1211 </li>
1212
1213
1214
1215
1216
1217
1218
1219 <li class="md-nav__item">
1220 <a href="../../package/pip/option/" class="md-nav__link">
1221 option
1222 </a>
1223 </li>
1224
1225
1226
1227
1228
1229
1230
1231 <li class="md-nav__item">
1232 <a href="../../package/pip/page/" class="md-nav__link">
1233 page
1234 </a>
1235 </li>
1236
1237
1238
1239
1240
1241
1242
1243 <li class="md-nav__item">
1244 <a href="../../package/pip/pip/" class="md-nav__link">
1245 pip
1246 </a>
1247 </li>
1248
1249
1250
1251
1252
1253
1254
1255 <li class="md-nav__item">
1256 <a href="../../package/pip/script/" class="md-nav__link">
1257 script
1258 </a>
1259 </li>
1260
1261
1262
1263
1264
1265
1266
1267 <li class="md-nav__item">
1268 <a href="../../package/pip/smiley/" class="md-nav__link">
1269 smiley
1270 </a>
1271 </li>
1272
1273
1274
1275
1276
1277
1278
1279 <li class="md-nav__item">
1280 <a href="../../package/pip/sql/" class="md-nav__link">
1281 sql
1282 </a>
1283 </li>
1284
1285
1286
1287
1288
1289
1290
1291 <li class="md-nav__item">
1292 <a href="../../package/pip/style/" class="md-nav__link">
1293 style
1294 </a>
1295 </li>
1296
1297
1298
1299
1300
1301
1302
1303 <li class="md-nav__item">
1304 <a href="../../package/pip/template/" class="md-nav__link">
1305 template
1306 </a>
1307 </li>
1308
1309
1310
1311
1312
1313
1314
1315 <li class="md-nav__item">
1316 <a href="../../package/pip/template-listener/" class="md-nav__link">
1317 templateListener
1318 </a>
1319 </li>
1320
1321
1322
1323
1324
1325
1326
1327 <li class="md-nav__item">
1328 <a href="../../package/pip/user-group-option/" class="md-nav__link">
1329 userGroupOption
1330 </a>
1331 </li>
1332
1333
1334
1335
1336
1337
1338
1339 <li class="md-nav__item">
1340 <a href="../../package/pip/user-menu/" class="md-nav__link">
1341 userMenu
1342 </a>
1343 </li>
1344
1345
1346
1347
1348
1349
1350
1351 <li class="md-nav__item">
1352 <a href="../../package/pip/user-notification-event/" class="md-nav__link">
1353 userNotificationEvent
1354 </a>
1355 </li>
1356
1357
1358
1359
1360
1361
1362
1363 <li class="md-nav__item">
1364 <a href="../../package/pip/user-option/" class="md-nav__link">
1365 userOption
1366 </a>
1367 </li>
1368
1369
1370
1371
1372
1373
1374
1375 <li class="md-nav__item">
1376 <a href="../../package/pip/user-profile-menu/" class="md-nav__link">
1377 userProfileMenu
1378 </a>
1379 </li>
1380
1381
1382
1383 </ul>
1384 </nav>
1385 </li>
1386
1387
1388
1389
1390
1391
1392
1393 <li class="md-nav__item">
1394 <a href="../../package/database-php-api/" class="md-nav__link">
1395 Database PHP API
1396 </a>
1397 </li>
1398
1399
1400
1401 </ul>
1402 </nav>
1403 </li>
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415 <li class="md-nav__item md-nav__item--nested">
1416
1417
1418 <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_6" type="checkbox" id="__nav_6" >
1419
1420 <label class="md-nav__link" for="__nav_6">
1421 Migration
1422 <span class="md-nav__icon md-icon"></span>
1423 </label>
1424 <nav class="md-nav" aria-label="Migration" data-md-level="1">
1425 <label class="md-nav__title" for="__nav_6">
1426 <span class="md-nav__icon md-icon"></span>
1427 Migration
1428 </label>
1429 <ul class="md-nav__list" data-md-scrollfix>
1430
1431
1432
1433
1434
1435
1436 <li class="md-nav__item md-nav__item--nested">
1437
1438
1439 <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_6_1" type="checkbox" id="__nav_6_1" >
1440
1441 <label class="md-nav__link" for="__nav_6_1">
1442 Migrating from WSC 5.3
1443 <span class="md-nav__icon md-icon"></span>
1444 </label>
1445 <nav class="md-nav" aria-label="Migrating from WSC 5.3" data-md-level="2">
1446 <label class="md-nav__title" for="__nav_6_1">
1447 <span class="md-nav__icon md-icon"></span>
1448 Migrating from WSC 5.3
1449 </label>
1450 <ul class="md-nav__list" data-md-scrollfix>
1451
1452
1453
1454
1455
1456 <li class="md-nav__item">
1457 <a href="../../migration/wsc53/php/" class="md-nav__link">
1458 PHP API
1459 </a>
1460 </li>
1461
1462
1463
1464
1465
1466
1467
1468 <li class="md-nav__item">
1469 <a href="../../migration/wsc53/session/" class="md-nav__link">
1470 Session Handling and Authentication
1471 </a>
1472 </li>
1473
1474
1475
1476
1477
1478
1479
1480 <li class="md-nav__item">
1481 <a href="../../migration/wsc53/javascript/" class="md-nav__link">
1482 JavaScript
1483 </a>
1484 </li>
1485
1486
1487
1488
1489
1490
1491
1492 <li class="md-nav__item">
1493 <a href="../../migration/wsc53/templates/" class="md-nav__link">
1494 Templates
1495 </a>
1496 </li>
1497
1498
1499
1500
1501
1502
1503
1504 <li class="md-nav__item">
1505 <a href="../../migration/wsc53/libraries/" class="md-nav__link">
1506 Third Party Libraries
1507 </a>
1508 </li>
1509
1510
1511
1512 </ul>
1513 </nav>
1514 </li>
1515
1516
1517
1518
1519
1520
1521
1522
1523 <li class="md-nav__item md-nav__item--nested">
1524
1525
1526 <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_6_2" type="checkbox" id="__nav_6_2" >
1527
1528 <label class="md-nav__link" for="__nav_6_2">
1529 Migrating from WSC 5.2
1530 <span class="md-nav__icon md-icon"></span>
1531 </label>
1532 <nav class="md-nav" aria-label="Migrating from WSC 5.2" data-md-level="2">
1533 <label class="md-nav__title" for="__nav_6_2">
1534 <span class="md-nav__icon md-icon"></span>
1535 Migrating from WSC 5.2
1536 </label>
1537 <ul class="md-nav__list" data-md-scrollfix>
1538
1539
1540
1541
1542
1543 <li class="md-nav__item">
1544 <a href="../../migration/wsc52/php/" class="md-nav__link">
1545 PHP API
1546 </a>
1547 </li>
1548
1549
1550
1551
1552
1553
1554
1555 <li class="md-nav__item">
1556 <a href="../../migration/wsc52/templates/" class="md-nav__link">
1557 Templates and Languages
1558 </a>
1559 </li>
1560
1561
1562
1563
1564
1565
1566
1567 <li class="md-nav__item">
1568 <a href="../../migration/wsc52/libraries/" class="md-nav__link">
1569 Third Party Libraries
1570 </a>
1571 </li>
1572
1573
1574
1575 </ul>
1576 </nav>
1577 </li>
1578
1579
1580
1581
1582
1583
1584
1585
1586 <li class="md-nav__item md-nav__item--nested">
1587
1588
1589 <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_6_3" type="checkbox" id="__nav_6_3" >
1590
1591 <label class="md-nav__link" for="__nav_6_3">
1592 Migrating from WSC 3.1
1593 <span class="md-nav__icon md-icon"></span>
1594 </label>
1595 <nav class="md-nav" aria-label="Migrating from WSC 3.1" data-md-level="2">
1596 <label class="md-nav__title" for="__nav_6_3">
1597 <span class="md-nav__icon md-icon"></span>
1598 Migrating from WSC 3.1
1599 </label>
1600 <ul class="md-nav__list" data-md-scrollfix>
1601
1602
1603
1604
1605
1606 <li class="md-nav__item">
1607 <a href="../../migration/wsc31/php/" class="md-nav__link">
1608 PHP API
1609 </a>
1610 </li>
1611
1612
1613
1614 </ul>
1615 </nav>
1616 </li>
1617
1618
1619
1620
1621
1622
1623
1624
1625 <li class="md-nav__item md-nav__item--nested">
1626
1627
1628 <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_6_4" type="checkbox" id="__nav_6_4" >
1629
1630 <label class="md-nav__link" for="__nav_6_4">
1631 Migrating from WSC 3.0
1632 <span class="md-nav__icon md-icon"></span>
1633 </label>
1634 <nav class="md-nav" aria-label="Migrating from WSC 3.0" data-md-level="2">
1635 <label class="md-nav__title" for="__nav_6_4">
1636 <span class="md-nav__icon md-icon"></span>
1637 Migrating from WSC 3.0
1638 </label>
1639 <ul class="md-nav__list" data-md-scrollfix>
1640
1641
1642
1643
1644
1645 <li class="md-nav__item">
1646 <a href="../../migration/wsc30/php/" class="md-nav__link">
1647 PHP API
1648 </a>
1649 </li>
1650
1651
1652
1653
1654
1655
1656
1657 <li class="md-nav__item">
1658 <a href="../../migration/wsc30/javascript/" class="md-nav__link">
1659 JavaScript API
1660 </a>
1661 </li>
1662
1663
1664
1665
1666
1667
1668
1669 <li class="md-nav__item">
1670 <a href="../../migration/wsc30/templates/" class="md-nav__link">
1671 Templates
1672 </a>
1673 </li>
1674
1675
1676
1677
1678
1679
1680
1681 <li class="md-nav__item">
1682 <a href="../../migration/wsc30/css/" class="md-nav__link">
1683 CSS
1684 </a>
1685 </li>
1686
1687
1688
1689
1690
1691
1692
1693 <li class="md-nav__item">
1694 <a href="../../migration/wsc30/package/" class="md-nav__link">
1695 Package Components
1696 </a>
1697 </li>
1698
1699
1700
1701 </ul>
1702 </nav>
1703 </li>
1704
1705
1706
1707
1708
1709
1710
1711
1712 <li class="md-nav__item md-nav__item--nested">
1713
1714
1715 <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_6_5" type="checkbox" id="__nav_6_5" >
1716
1717 <label class="md-nav__link" for="__nav_6_5">
1718 Migrating from WCF 2.1
1719 <span class="md-nav__icon md-icon"></span>
1720 </label>
1721 <nav class="md-nav" aria-label="Migrating from WCF 2.1" data-md-level="2">
1722 <label class="md-nav__title" for="__nav_6_5">
1723 <span class="md-nav__icon md-icon"></span>
1724 Migrating from WCF 2.1
1725 </label>
1726 <ul class="md-nav__list" data-md-scrollfix>
1727
1728
1729
1730
1731
1732 <li class="md-nav__item">
1733 <a href="../../migration/wcf21/php/" class="md-nav__link">
1734 PHP API
1735 </a>
1736 </li>
1737
1738
1739
1740
1741
1742
1743
1744 <li class="md-nav__item">
1745 <a href="../../migration/wcf21/templates/" class="md-nav__link">
1746 Templates
1747 </a>
1748 </li>
1749
1750
1751
1752
1753
1754
1755
1756 <li class="md-nav__item">
1757 <a href="../../migration/wcf21/css/" class="md-nav__link">
1758 CSS
1759 </a>
1760 </li>
1761
1762
1763
1764
1765
1766
1767
1768 <li class="md-nav__item">
1769 <a href="../../migration/wcf21/package/" class="md-nav__link">
1770 Package Components
1771 </a>
1772 </li>
1773
1774
1775
1776 </ul>
1777 </nav>
1778 </li>
1779
1780
1781
1782 </ul>
1783 </nav>
1784 </li>
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796 <li class="md-nav__item md-nav__item--nested">
1797
1798
1799 <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_7" type="checkbox" id="__nav_7" >
1800
1801 <label class="md-nav__link" for="__nav_7">
1802 Tutorials
1803 <span class="md-nav__icon md-icon"></span>
1804 </label>
1805 <nav class="md-nav" aria-label="Tutorials" data-md-level="1">
1806 <label class="md-nav__title" for="__nav_7">
1807 <span class="md-nav__icon md-icon"></span>
1808 Tutorials
1809 </label>
1810 <ul class="md-nav__list" data-md-scrollfix>
1811
1812
1813
1814
1815
1816
1817 <li class="md-nav__item md-nav__item--nested">
1818
1819
1820 <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_7_1" type="checkbox" id="__nav_7_1" >
1821
1822 <label class="md-nav__link" for="__nav_7_1">
1823 Tutorial Series
1824 <span class="md-nav__icon md-icon"></span>
1825 </label>
1826 <nav class="md-nav" aria-label="Tutorial Series" data-md-level="2">
1827 <label class="md-nav__title" for="__nav_7_1">
1828 <span class="md-nav__icon md-icon"></span>
1829 Tutorial Series
1830 </label>
1831 <ul class="md-nav__list" data-md-scrollfix>
1832
1833
1834
1835
1836
1837 <li class="md-nav__item">
1838 <a href="../../tutorial/series/overview/" class="md-nav__link">
1839 Overview
1840 </a>
1841 </li>
1842
1843
1844
1845
1846
1847
1848
1849 <li class="md-nav__item">
1850 <a href="../../tutorial/series/part_1/" class="md-nav__link">
1851 Part 1
1852 </a>
1853 </li>
1854
1855
1856
1857
1858
1859
1860
1861 <li class="md-nav__item">
1862 <a href="../../tutorial/series/part_2/" class="md-nav__link">
1863 Part 2
1864 </a>
1865 </li>
1866
1867
1868
1869
1870
1871
1872
1873 <li class="md-nav__item">
1874 <a href="../../tutorial/series/part_3/" class="md-nav__link">
1875 Part 3
1876 </a>
1877 </li>
1878
1879
1880
1881 </ul>
1882 </nav>
1883 </li>
1884
1885
1886
1887 </ul>
1888 </nav>
1889 </li>
1890
1891
1892
1893 </ul>
1894 </nav>
1895 </div>
1896 </div>
1897 </div>
1898
1899
1900
1901 <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
1902 <div class="md-sidebar__scrollwrap">
1903 <div class="md-sidebar__inner">
1904
1905 <nav class="md-nav md-nav--secondary" aria-label="Table of contents">
1906
1907
1908
1909
1910
1911 <label class="md-nav__title" for="__toc">
1912 <span class="md-nav__icon md-icon"></span>
1913 Table of contents
1914 </label>
1915 <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
1916
1917 <li class="md-nav__item">
1918 <a href="#databaseobject" class="md-nav__link">
1919 DatabaseObject
1920 </a>
1921
1922 </li>
1923
1924 <li class="md-nav__item">
1925 <a href="#databaseobjectdecorator" class="md-nav__link">
1926 DatabaseObjectDecorator
1927 </a>
1928
1929 </li>
1930
1931 <li class="md-nav__item">
1932 <a href="#databaseobjecteditor" class="md-nav__link">
1933 DatabaseObjectEditor
1934 </a>
1935
1936 <nav class="md-nav" aria-label="DatabaseObjectEditor">
1937 <ul class="md-nav__list">
1938
1939 <li class="md-nav__item">
1940 <a href="#create-a-new-row" class="md-nav__link">
1941 Create a new row
1942 </a>
1943
1944 </li>
1945
1946 <li class="md-nav__item">
1947 <a href="#updating-an-existing-row" class="md-nav__link">
1948 Updating an existing row
1949 </a>
1950
1951 </li>
1952
1953 <li class="md-nav__item">
1954 <a href="#deleting-a-row" class="md-nav__link">
1955 Deleting a row
1956 </a>
1957
1958 </li>
1959
1960 </ul>
1961 </nav>
1962
1963 </li>
1964
1965 <li class="md-nav__item">
1966 <a href="#databaseobjectlist" class="md-nav__link">
1967 DatabaseObjectList
1968 </a>
1969
1970 </li>
1971
1972 <li class="md-nav__item">
1973 <a href="#abstractdatabaseobjectaction" class="md-nav__link">
1974 AbstractDatabaseObjectAction
1975 </a>
1976
1977 <nav class="md-nav" aria-label="AbstractDatabaseObjectAction">
1978 <ul class="md-nav__list">
1979
1980 <li class="md-nav__item">
1981 <a href="#executing-an-action" class="md-nav__link">
1982 Executing an Action
1983 </a>
1984
1985 </li>
1986
1987 <li class="md-nav__item">
1988 <a href="#custom-method-with-ajax-support" class="md-nav__link">
1989 Custom Method with AJAX Support
1990 </a>
1991
1992 <nav class="md-nav" aria-label="Custom Method with AJAX Support">
1993 <ul class="md-nav__list">
1994
1995 <li class="md-nav__item">
1996 <a href="#ajax-validation" class="md-nav__link">
1997 AJAX Validation
1998 </a>
1999
2000 </li>
2001
2002 <li class="md-nav__item">
2003 <a href="#create-update-and-delete" class="md-nav__link">
2004 create, update and delete
2005 </a>
2006
2007 </li>
2008
2009 <li class="md-nav__item">
2010 <a href="#allow-invokation-by-guests" class="md-nav__link">
2011 Allow Invokation by Guests
2012 </a>
2013
2014 </li>
2015
2016 <li class="md-nav__item">
2017 <a href="#acp-access-only" class="md-nav__link">
2018 ACP Access Only
2019 </a>
2020
2021 </li>
2022
2023 </ul>
2024 </nav>
2025
2026 </li>
2027
2028 </ul>
2029 </nav>
2030
2031 </li>
2032
2033 </ul>
2034
2035 </nav>
2036 </div>
2037 </div>
2038 </div>
2039
2040
2041 <div class="md-content" data-md-component="content">
2042 <article class="md-content__inner md-typeset">
2043
2044
2045
2046 <h1 id="database-objects">Database Objects<a class="headerlink" href="#database-objects" title="Permanent link">#</a></h1>
2047 <p>WoltLab Suite uses a unified interface to work with database rows using an object based approach instead of using native arrays holding arbitrary data. Each database table is mapped to a model class that is designed to hold a single record from that table and expose methods to work with the stored data, for example providing assistance when working with normalized datasets.</p>
2048 <p>Developers are required to provide the proper DatabaseObject implementations themselves, they're not automatically generated, all though the actual code that needs to be written is rather small. The following examples assume the fictional database table <code>wcf1_example</code>, <code>exampleID</code> as the auto-incrementing primary key and the column <code>bar</code> to store some text.</p>
2049 <h2 id="databaseobject">DatabaseObject<a class="headerlink" href="#databaseobject" title="Permanent link">#</a></h2>
2050 <p>The basic model derives from <code>wcf\data\DatabaseObject</code> and provides a convenient constructor to fetch a single row or construct an instance using pre-loaded rows.</p>
2051 <div class="highlight"><pre><span></span><code><span class="o">&lt;?</span><span class="nx">php</span>
2052 <span class="k">namespace</span> <span class="nx">wcf\data\example</span><span class="p">;</span>
2053 <span class="k">use</span> <span class="nx">wcf\data\DatabaseObject</span><span class="p">;</span>
2054
2055 <span class="k">class</span> <span class="nc">Example</span> <span class="k">extends</span> <span class="nx">DatabaseObject</span> <span class="p">{}</span>
2056 </code></pre></div>
2057 <p>The class is intended to be empty by default and there only needs to be code if you want to add additional logic to your model. Both the class name and primary key are determined by <code>DatabaseObject</code> using the namespace and class name of the derived class. The example above uses the namespace <code>wcf\…</code> which is used as table prefix and the class name <code>Example</code> is converted into <code>exampleID</code>, resulting in the database table name <code>wcfN_example</code> with the primary key <code>exampleID</code>.</p>
2058 <p>You can prevent this automatic guessing by setting the class properties <code>$databaseTableName</code> and <code>$databaseTableIndexName</code> manually.</p>
2059 <h2 id="databaseobjectdecorator">DatabaseObjectDecorator<a class="headerlink" href="#databaseobjectdecorator" title="Permanent link">#</a></h2>
2060 <p>If you already have a <code>DatabaseObject</code> class and would like to extend it with additional data or methods, for example by providing a class <code>ViewableExample</code> which features view-related changes without polluting the original object, you can use <code>DatabaseObjectDecorator</code> which a default implementation of a decorator for database objects.</p>
2061 <div class="highlight"><pre><span></span><code><span class="o">&lt;?</span><span class="nx">php</span>
2062 <span class="k">namespace</span> <span class="nx">wcf\data\example</span><span class="p">;</span>
2063 <span class="k">use</span> <span class="nx">wcf\data\DatabaseObjectDecorator</span><span class="p">;</span>
2064
2065 <span class="k">class</span> <span class="nc">ViewableExample</span> <span class="k">extends</span> <span class="nx">DatabaseObjectDecorator</span> <span class="p">{</span>
2066 <span class="k">protected</span> <span class="k">static</span> <span class="nv">$baseClass</span> <span class="o">=</span> <span class="nx">Example</span><span class="o">::</span><span class="na">class</span><span class="p">;</span>
2067
2068 <span class="k">public</span> <span class="k">function</span> <span class="nf">getOutput</span><span class="p">()</span> <span class="p">{</span>
2069 <span class="nv">$output</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">;</span>
2070
2071 <span class="c1">// [determine output]</span>
2072
2073 <span class="k">return</span> <span class="nv">$output</span><span class="p">;</span>
2074 <span class="p">}</span>
2075 <span class="p">}</span>
2076 </code></pre></div>
2077 <p>It is mandatory to set the static <code>$baseClass</code> property to the name of the decorated class.</p>
2078 <p>Like for any decorator, you can directly access the decorated object's properties and methods for a decorated object by accessing the property or calling the method on the decorated object.
2079 You can access the decorated objects directly via <code>DatabaseObjectDecorator::getDecoratedObject()</code>.</p>
2080 <h2 id="databaseobjecteditor">DatabaseObjectEditor<a class="headerlink" href="#databaseobjecteditor" title="Permanent link">#</a></h2>
2081 <div class="admonition info">
2082 <p class="admonition-title">This is the low-level interface to manipulate data rows, it is recommended to use <code>AbstractDatabaseObjectAction</code>.</p>
2083 </div>
2084 <p>Adding, editing and deleting models is done using the <code>DatabaseObjectEditor</code> class that decorates a <code>DatabaseObject</code> and uses its data to perform the actions.</p>
2085 <div class="highlight"><pre><span></span><code><span class="o">&lt;?</span><span class="nx">php</span>
2086 <span class="k">namespace</span> <span class="nx">wcf\data\example</span><span class="p">;</span>
2087 <span class="k">use</span> <span class="nx">wcf\data\DatabaseObjectEditor</span><span class="p">;</span>
2088
2089 <span class="k">class</span> <span class="nc">ExampleEditor</span> <span class="k">extends</span> <span class="nx">DatabaseObjectEditor</span> <span class="p">{</span>
2090 <span class="k">protected</span> <span class="k">static</span> <span class="nv">$baseClass</span> <span class="o">=</span> <span class="nx">Example</span><span class="o">::</span><span class="na">class</span><span class="p">;</span>
2091 <span class="p">}</span>
2092 </code></pre></div>
2093 <p>The editor class requires you to provide the fully qualified name of the model, that is the class name including the complete namespace. Database table name and index key will be pulled directly from the model.</p>
2094 <h3 id="create-a-new-row">Create a new row<a class="headerlink" href="#create-a-new-row" title="Permanent link">#</a></h3>
2095 <p>Inserting a new row into the database table is provided through <code>DatabaseObjectEditor::create()</code> which yields a <code>DatabaseObject</code> instance after creation.</p>
2096 <div class="highlight"><pre><span></span><code><span class="o">&lt;?</span><span class="nx">php</span>
2097 <span class="nv">$example</span> <span class="o">=</span> <span class="nx">\wcf\data\example\ExampleEditor</span><span class="o">::</span><span class="na">create</span><span class="p">([</span>
2098 <span class="s1">&#39;bar&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;Hello World!&#39;</span>
2099 <span class="p">]);</span>
2100
2101 <span class="c1">// output: Hello World!</span>
2102 <span class="k">echo</span> <span class="nv">$example</span><span class="o">-&gt;</span><span class="na">bar</span><span class="p">;</span>
2103 </code></pre></div>
2104 <h3 id="updating-an-existing-row">Updating an existing row<a class="headerlink" href="#updating-an-existing-row" title="Permanent link">#</a></h3>
2105 <div class="admonition warning">
2106 <p class="admonition-title">The internal state of the decorated <code>DatabaseObject</code> is not altered at any point, the values will still be the same after editing or deleting the represented row. If you need an object with the latest data, you'll have to discard the current object and refetch the data from database.</p>
2107 </div>
2108 <div class="highlight"><pre><span></span><code><span class="o">&lt;?</span><span class="nx">php</span>
2109 <span class="nv">$example</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\wcf\data\example\Example</span><span class="p">(</span><span class="nv">$id</span><span class="p">);</span>
2110 <span class="nv">$exampleEditor</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\wcf\data\example\ExampleEditor</span><span class="p">(</span><span class="nv">$example</span><span class="p">);</span>
2111 <span class="nv">$exampleEditor</span><span class="o">-&gt;</span><span class="na">update</span><span class="p">([</span>
2112 <span class="s1">&#39;bar&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;baz&#39;</span>
2113 <span class="p">]);</span>
2114
2115 <span class="c1">// output: Hello World!</span>
2116 <span class="k">echo</span> <span class="nv">$example</span><span class="o">-&gt;</span><span class="na">bar</span><span class="p">;</span>
2117
2118 <span class="c1">// re-creating the object will query the database again and retrieve the updated value</span>
2119 <span class="nv">$example</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\wcf\data\example\Example</span><span class="p">(</span><span class="nv">$example</span><span class="o">-&gt;</span><span class="na">id</span><span class="p">);</span>
2120
2121 <span class="c1">// output: baz</span>
2122 <span class="k">echo</span> <span class="nv">$example</span><span class="o">-&gt;</span><span class="na">bar</span><span class="p">;</span>
2123 </code></pre></div>
2124 <h3 id="deleting-a-row">Deleting a row<a class="headerlink" href="#deleting-a-row" title="Permanent link">#</a></h3>
2125 <div class="admonition warning">
2126 <p class="admonition-title">Similar to the update process, the decorated <code>DatabaseObject</code> is not altered and will then point to an inexistent row.</p>
2127 </div>
2128 <div class="highlight"><pre><span></span><code><span class="o">&lt;?</span><span class="nx">php</span>
2129 <span class="nv">$example</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\wcf\data\example\Example</span><span class="p">(</span><span class="nv">$id</span><span class="p">);</span>
2130 <span class="nv">$exampleEditor</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\wcf\data\example\ExampleEditor</span><span class="p">(</span><span class="nv">$example</span><span class="p">);</span>
2131 <span class="nv">$exampleEditor</span><span class="o">-&gt;</span><span class="na">delete</span><span class="p">();</span>
2132 </code></pre></div>
2133 <h2 id="databaseobjectlist">DatabaseObjectList<a class="headerlink" href="#databaseobjectlist" title="Permanent link">#</a></h2>
2134 <p>Every row is represented as a single instance of the model, but the instance creation deals with single rows only. Retrieving larger sets of rows would be quite inefficient due to the large amount of queries that will be dispatched. This is solved with the <code>DatabaseObjectList</code> object that exposes an interface to query the database table using arbitrary conditions for data selection. All rows will be fetched using a single query and the resulting rows are automatically loaded into separate models.</p>
2135 <div class="highlight"><pre><span></span><code><span class="o">&lt;?</span><span class="nx">php</span>
2136 <span class="k">namespace</span> <span class="nx">wcf\data\example</span><span class="p">;</span>
2137 <span class="k">use</span> <span class="nx">wcf\data\DatabaseObjectList</span><span class="p">;</span>
2138
2139 <span class="k">class</span> <span class="nc">ExampleList</span> <span class="k">extends</span> <span class="nx">DatabaseObjectList</span> <span class="p">{</span>
2140 <span class="k">public</span> <span class="nv">$className</span> <span class="o">=</span> <span class="nx">Example</span><span class="o">::</span><span class="na">class</span><span class="p">;</span>
2141 <span class="p">}</span>
2142 </code></pre></div>
2143 <p>The following code listing illustrates loading a large set of examples and iterating over the list to retrieve the objects.</p>
2144 <div class="highlight"><pre><span></span><code><span class="o">&lt;?</span><span class="nx">php</span>
2145 <span class="nv">$exampleList</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\wcf\data\example\ExampleList</span><span class="p">();</span>
2146 <span class="c1">// add constraints using the condition builder</span>
2147 <span class="nv">$exampleList</span><span class="o">-&gt;</span><span class="na">getConditionBuilder</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">add</span><span class="p">(</span><span class="s1">&#39;bar IN (?)&#39;</span><span class="p">,</span> <span class="p">[[</span><span class="s1">&#39;Hello World!&#39;</span><span class="p">,</span> <span class="s1">&#39;bar&#39;</span><span class="p">,</span> <span class="s1">&#39;baz&#39;</span><span class="p">]]);</span>
2148 <span class="c1">// actually read the rows</span>
2149 <span class="nv">$exampleList</span><span class="o">-&gt;</span><span class="na">readObjects</span><span class="p">();</span>
2150 <span class="k">foreach</span> <span class="p">(</span><span class="nv">$exampleList</span> <span class="k">as</span> <span class="nv">$example</span><span class="p">)</span> <span class="p">{</span>
2151 <span class="k">echo</span> <span class="nv">$example</span><span class="o">-&gt;</span><span class="na">bar</span><span class="p">;</span>
2152 <span class="p">}</span>
2153
2154 <span class="c1">// retrieve the models directly instead of iterating over them</span>
2155 <span class="nv">$examples</span> <span class="o">=</span> <span class="nv">$exampleList</span><span class="o">-&gt;</span><span class="na">getObjects</span><span class="p">();</span>
2156
2157 <span class="c1">// just retrieve the number of rows</span>
2158 <span class="nv">$exampleCount</span> <span class="o">=</span> <span class="nv">$exampleList</span><span class="o">-&gt;</span><span class="na">countObjects</span><span class="p">();</span>
2159 </code></pre></div>
2160 <p><code>DatabaseObjectList</code> implements both <a href="https://secure.php.net/manual/en/class.seekableiterator.php">SeekableIterator</a> and <a href="https://secure.php.net/manual/en/class.countable.php">Countable</a>.</p>
2161 <p>Additionally, <code>DatabaseObjectList</code> objects has the following three public properties that are useful when fetching data with lists:</p>
2162 <ul>
2163 <li><code>$sqlLimit</code> determines how many rows are fetched.
2164 If its value is <code>0</code> (which is the default value), all results are fetched.
2165 So be careful when dealing with large tables and you only want a limited number of rows:
2166 Set <code>$sqlLimit</code> to a value larger than zero!</li>
2167 <li><code>$sqlOffset</code>:
2168 Paginated pages like a thread list use this feature a lot, it allows you to skip a given number of results.
2169 Imagine you want to display 20 threads per page but there are a total of 60 threads available.
2170 In this case you would specify <code>$sqlLimit = 20</code> and <code>$sqlOffset = 20</code> which will skip the first 20 threads, effectively displaying thread 21 to 40.</li>
2171 <li><code>$sqlOrderBy</code> determines by which column(s) the rows are sorted in which order.
2172 Using our example in <code>$sqlOffset</code> you might want to display the 20 most recent threads on page 1, thus you should specify the order field and its direction, e.g. <code>$sqlOrderBy = 'thread.lastPostTime DESC'</code> which returns the most recent thread first.</li>
2173 </ul>
2174 <p>For more advanced usage, there two additional fields that deal with the type of objects returned.
2175 First, let's go into a bit more detail what setting the <code>$className</code> property actually does:</p>
2176 <ol>
2177 <li>It is the type of database object in which the rows are wrapped.</li>
2178 <li>It determines which database table is actually queried and which index is used (see the <code>$databaseTableName</code> and <code>$databaseTableIndexName</code> properties of <code>DatabaseObject</code>).</li>
2179 </ol>
2180 <p>Sometimes you might use the database table of some database object but wrap the rows in another database object.
2181 This can be achieved by setting the <code>$objectClassName</code> property to the desired class name.</p>
2182 <p>In other cases, you might want to wrap the created objects in a database object decorator which can be done by setting the <code>$decoratorClassName</code> property to the desired class name:</p>
2183 <div class="highlight"><pre><span></span><code><span class="o">&lt;?</span><span class="nx">php</span>
2184 <span class="nv">$exampleList</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\wcf\data\example\ExampleList</span><span class="p">();</span>
2185 <span class="nv">$exampleList</span><span class="o">-&gt;</span><span class="na">decoratorClassName</span> <span class="o">=</span> <span class="nx">\wcf\data\example\ViewableExample</span><span class="o">::</span><span class="na">class</span><span class="p">;</span>
2186 </code></pre></div>
2187 <p>Of course, you do not have to set the property after creating the list object, you can also set it by creating a dedicated class:</p>
2188 <div class="highlight"><pre><span></span><code><span class="o">&lt;?</span><span class="nx">php</span>
2189 <span class="k">namespace</span> <span class="nx">wcf\data\example</span><span class="p">;</span>
2190
2191 <span class="k">class</span> <span class="nc">ViewableExampleList</span> <span class="k">extends</span> <span class="nx">ExampleList</span> <span class="p">{</span>
2192 <span class="k">public</span> <span class="nv">$decoratorClassName</span> <span class="o">=</span> <span class="nx">ViewableExample</span><span class="o">::</span><span class="na">class</span><span class="p">;</span>
2193 <span class="p">}</span>
2194 </code></pre></div>
2195 <h2 id="abstractdatabaseobjectaction">AbstractDatabaseObjectAction<a class="headerlink" href="#abstractdatabaseobjectaction" title="Permanent link">#</a></h2>
2196 <p>Row creation and manipulation can be performed using the aforementioned <code>DatabaseObjectEditor</code> class, but this approach has two major issues:</p>
2197 <ol>
2198 <li>Row creation, update and deletion takes place silently without notifying any other components.</li>
2199 <li>Data is passed to the database adapter without any further processing.</li>
2200 </ol>
2201 <p>The <code>AbstractDatabaseObjectAction</code> solves both problems by wrapping around the editor class and thus provide an additional layer between the action that should be taken and the actual process. The first problem is solved by a fixed set of events being fired, the second issue is addressed by having a single entry point for all data editing.</p>
2202 <div class="highlight"><pre><span></span><code><span class="o">&lt;?</span><span class="nx">php</span>
2203 <span class="k">namespace</span> <span class="nx">wcf\data\example</span><span class="p">;</span>
2204 <span class="k">use</span> <span class="nx">wcf\data\AbstractDatabaseObjectAction</span><span class="p">;</span>
2205
2206 <span class="k">class</span> <span class="nc">ExampleAction</span> <span class="k">extends</span> <span class="nx">AbstractDatabaseObjectAction</span> <span class="p">{</span>
2207 <span class="k">public</span> <span class="nv">$className</span> <span class="o">=</span> <span class="nx">ExampleEditor</span><span class="o">::</span><span class="na">class</span><span class="p">;</span>
2208 <span class="p">}</span>
2209 </code></pre></div>
2210 <h3 id="executing-an-action">Executing an Action<a class="headerlink" href="#executing-an-action" title="Permanent link">#</a></h3>
2211 <div class="admonition warning">
2212 <p class="admonition-title">The method <code>AbstractDatabaseObjectAction::validateAction()</code> is internally used for AJAX method invocation and must not be called programmatically.</p>
2213 </div>
2214 <p>The next example represents the same functionality as seen for <code>DatabaseObjectEditor</code>:</p>
2215 <div class="highlight"><pre><span></span><code><span class="o">&lt;?</span><span class="nx">php</span>
2216 <span class="k">use</span> <span class="nx">wcf\data\example\ExampleAction</span><span class="p">;</span>
2217
2218 <span class="c1">// create a row</span>
2219 <span class="nv">$exampleAction</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ExampleAction</span><span class="p">([],</span> <span class="s1">&#39;create&#39;</span><span class="p">,</span> <span class="p">[</span>
2220 <span class="s1">&#39;data&#39;</span> <span class="o">=&gt;</span> <span class="p">[</span><span class="s1">&#39;bar&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;Hello World&#39;</span><span class="p">]</span>
2221 <span class="p">]);</span>
2222 <span class="nv">$example</span> <span class="o">=</span> <span class="nv">$exampleAction</span><span class="o">-&gt;</span><span class="na">executeAction</span><span class="p">()[</span><span class="s1">&#39;returnValues&#39;</span><span class="p">];</span>
2223
2224 <span class="c1">// update a row using the id</span>
2225 <span class="nv">$exampleAction</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ExampleAction</span><span class="p">([</span><span class="mi">1</span><span class="p">],</span> <span class="s1">&#39;update&#39;</span><span class="p">,</span> <span class="p">[</span>
2226 <span class="s1">&#39;data&#39;</span> <span class="o">=&gt;</span> <span class="p">[</span><span class="s1">&#39;bar&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;baz&#39;</span><span class="p">]</span>
2227 <span class="p">]);</span>
2228 <span class="nv">$exampleAction</span><span class="o">-&gt;</span><span class="na">executeAction</span><span class="p">();</span>
2229
2230 <span class="c1">// delete a row using a model</span>
2231 <span class="nv">$exampleAction</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ExampleAction</span><span class="p">([</span><span class="nv">$example</span><span class="p">],</span> <span class="s1">&#39;delete&#39;</span><span class="p">);</span>
2232 <span class="nv">$exampleAction</span><span class="o">-&gt;</span><span class="na">executeAction</span><span class="p">();</span>
2233 </code></pre></div>
2234 <p>You can access the return values both by storing the return value of <code>executeAction()</code> or by retrieving it via <code>getReturnValues()</code>.</p>
2235 <p><span class="label label-info">Events</span> <code>initializeAction</code>, <code>validateAction</code> and <code>finalizeAction</code></p>
2236 <h3 id="custom-method-with-ajax-support">Custom Method with AJAX Support<a class="headerlink" href="#custom-method-with-ajax-support" title="Permanent link">#</a></h3>
2237 <p>This section is about adding the method <code>baz()</code> to <code>ExampleAction</code> and calling it via AJAX.</p>
2238 <h4 id="ajax-validation">AJAX Validation<a class="headerlink" href="#ajax-validation" title="Permanent link">#</a></h4>
2239 <p>Methods of an action cannot be called via AJAX, unless they have a validation method. This means that <code>ExampleAction</code> must define both a <code>public function baz()</code> and <code>public function validateBaz()</code>, the name for the validation method is constructed by upper-casing the first character of the method name and prepending <code>validate</code>.</p>
2240 <p>The lack of the companion <code>validate*</code> method will cause the AJAX proxy to deny the request instantaneously. Do not add a validation method if you don't want it to be callable via AJAX ever!</p>
2241 <h4 id="create-update-and-delete">create, update and delete<a class="headerlink" href="#create-update-and-delete" title="Permanent link">#</a></h4>
2242 <p>The methods <code>create</code>, <code>update</code> and <code>delete</code> are available for all classes deriving from <code>AbstractDatabaseObjectAction</code> and directly pass the input data to the <code>DatabaseObjectEditor</code>. These methods deny access to them via AJAX by default, unless you explicitly enable access. Depending on your case, there are two different strategies to enable AJAX access to them.</p>
2243 <div class="highlight"><pre><span></span><code><span class="o">&lt;?</span><span class="nx">php</span>
2244 <span class="k">namespace</span> <span class="nx">wcf\data\example</span><span class="p">;</span>
2245 <span class="k">use</span> <span class="nx">wcf\data\AbstractDatabaseObjectAction</span><span class="p">;</span>
2246
2247 <span class="k">class</span> <span class="nc">ExampleAction</span> <span class="k">extends</span> <span class="nx">AbstractDatabaseObjectAction</span> <span class="p">{</span>
2248 <span class="c1">// `create()` can now be called via AJAX if the requesting user posses the listed permissions</span>
2249 <span class="k">protected</span> <span class="nv">$permissionsCreate</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;admin.example.canManageExample&#39;</span><span class="p">];</span>
2250
2251 <span class="k">public</span> <span class="k">function</span> <span class="nf">validateUpdate</span><span class="p">()</span> <span class="p">{</span>
2252 <span class="c1">// your very own validation logic that does not make use of the</span>
2253 <span class="c1">// built-in `$permissionsUpdate` property</span>
2254
2255 <span class="c1">// you can still invoke the built-in permissions check if you like to</span>
2256 <span class="k">parent</span><span class="o">::</span><span class="na">validateUpdate</span><span class="p">();</span>
2257 <span class="p">}</span>
2258 <span class="p">}</span>
2259 </code></pre></div>
2260 <h4 id="allow-invokation-by-guests">Allow Invokation by Guests<a class="headerlink" href="#allow-invokation-by-guests" title="Permanent link">#</a></h4>
2261 <p>Invoking methods is restricted to logged-in users by default and the only way to override this behavior is to alter the property <code>$allowGuestAccess</code>. It is a simple string array that is expected to hold all methods that should be accessible by users, excluding their companion validation methods.</p>
2262 <h4 id="acp-access-only">ACP Access Only<a class="headerlink" href="#acp-access-only" title="Permanent link">#</a></h4>
2263 <p>Method access is usually limited by permissions, but sometimes there might be the need for some added security to avoid mistakes. The <code>$requireACP</code> property works similar to <code>$allowGuestAccess</code>, but enforces the request to originate from the ACP together with a valid ACP session, ensuring that only users able to access the ACP can actually invoke these methods.</p>
2264
2265
2266
2267
2268
2269
2270
2271 </article>
2272 </div>
2273 </div>
2274 </main>
2275
2276
2277 <footer class="md-footer">
2278
2279 <nav class="md-footer__inner md-grid" aria-label="Footer">
2280
2281 <a href="../pages/" class="md-footer__link md-footer__link--prev" rel="prev">
2282 <div class="md-footer__button md-icon">
2283 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg>
2284 </div>
2285 <div class="md-footer__title">
2286 <div class="md-ellipsis">
2287 <span class="md-footer__direction">
2288 Previous
2289 </span>
2290 Pages
2291 </div>
2292 </div>
2293 </a>
2294
2295
2296 <a href="../database-access/" class="md-footer__link md-footer__link--next" rel="next">
2297 <div class="md-footer__title">
2298 <div class="md-ellipsis">
2299 <span class="md-footer__direction">
2300 Next
2301 </span>
2302 Database Access
2303 </div>
2304 </div>
2305 <div class="md-footer__button md-icon">
2306 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4z"/></svg>
2307 </div>
2308 </a>
2309
2310 </nav>
2311
2312 <div class="md-footer-meta md-typeset">
2313 <div class="md-footer-meta__inner md-grid">
2314 <div class="md-footer-copyright">
2315
2316 <div class="md-footer-copyright__highlight">
2317 Copyright © 2020 WoltLab GmbH
2318 </div>
2319
2320 Made with
2321 <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
2322 Material for MkDocs
2323 </a>
2324
2325 </div>
2326 <div class="md-footer-copyright">
2327 <a href="https://www.woltlab.com/legal-notice/">Legal Notice</a>
2328 <a href="https://www.woltlab.com/privacy-policy/">Privacy Policy</a>
2329 </div>
2330 </div>
2331 </div>
2332 </footer>
2333
2334 </div>
2335 <div class="md-dialog" data-md-component="dialog">
2336 <div class="md-dialog__inner md-typeset"></div>
2337 </div>
2338 <script id="__config" type="application/json">{"base": "../..", "features": [], "translations": {"clipboard.copy": "Copy to clipboard", "clipboard.copied": "Copied to clipboard", "search.config.lang": "en", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Search", "search.result.placeholder": "Type to start searching", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.term.missing": "Missing"}, "search": "../../assets/javascripts/workers/search.fb4a9340.min.js", "version": {"provider": "mike"}}</script>
2339
2340
2341 <script src="../../assets/javascripts/bundle.5cf3e710.min.js"></script>
2342
2343
2344 </body>
2345 </html>