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