You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -97,14 +97,16 @@ On the server side we need to register a callback that is executed once the requ
97
97
98
98
This route calls the controller **OCA\\notestutorial\\PageController->index()** method which is defined in **notestutorial/lib/Controller/PageController.php**. The controller returns a :doc:`template <../basics/front-end/templates>`, in this case **notestutorial/templates/main.php**:
99
99
100
-
.. note:: **@NoAdminRequired** and **@NoCSRFRequired** in the comments above the method turn off security checks, see `Authentication on Controllers <../basics/controllers.html#authentication>`__
100
+
.. note:: The ``#[NoAdminRequired]`` and ``#[NoCSRFRequired]`` attributes on the methods turn off security checks, see `Authentication on Controllers <../basics/controllers.html#authentication>`__
101
101
102
102
.. code-block:: php
103
103
104
104
<?php
105
105
namespace OCA\NotesTutorial\Controller;
106
106
107
107
use OCP\IRequest;
108
+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
109
+
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
108
110
use OCP\AppFramework\Http\TemplateResponse;
109
111
use OCP\AppFramework\Controller;
110
112
@@ -114,10 +116,8 @@ This route calls the controller **OCA\\notestutorial\\PageController->index()**
114
116
parent::__construct($appName, $request);
115
117
}
116
118
117
-
/**
118
-
* @NoAdminRequired
119
-
* @NoCSRFRequired
120
-
*/
119
+
#[NoAdminRequired]
120
+
#[NoCSRFRequired]
121
121
public function index() {
122
122
return new TemplateResponse('notestutorial', 'main');
123
123
}
@@ -133,63 +133,41 @@ Since the route which returns the initial HTML has been taken care of, the contr
133
133
134
134
use OCP\IRequest;
135
135
use OCP\AppFramework\Controller;
136
+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
136
137
137
138
class NoteController extends Controller {
138
139
139
140
public function __construct(string $appName, IRequest $request){
140
141
parent::__construct($appName, $request);
141
142
}
142
143
143
-
/**
144
-
* @NoAdminRequired
145
-
*/
144
+
#[NoAdminRequired]
146
145
public function index() {
147
146
// empty for now
148
147
}
149
148
150
-
/**
151
-
* @NoAdminRequired
152
-
*
153
-
* @param int $id
154
-
*/
149
+
#[NoAdminRequired]
155
150
public function show(int $id) {
156
151
// empty for now
157
152
}
158
153
159
-
/**
160
-
* @NoAdminRequired
161
-
*
162
-
* @param string $title
163
-
* @param string $content
164
-
*/
154
+
#[NoAdminRequired]
165
155
public function create(string $title, string $content) {
166
156
// empty for now
167
157
}
168
158
169
-
/**
170
-
* @NoAdminRequired
171
-
*
172
-
* @param int $id
173
-
* @param string $title
174
-
* @param string $content
175
-
*/
159
+
#[NoAdminRequired]
176
160
public function update(int $id, string $title, string $content) {
177
161
// empty for now
178
162
}
179
163
180
-
/**
181
-
* @NoAdminRequired
182
-
*
183
-
* @param int $id
184
-
*/
164
+
#[NoAdminRequired]
185
165
public function destroy(int $id) {
186
166
// empty for now
187
167
}
188
168
189
169
}
190
170
191
-
.. note:: The parameters are extracted from the request body and the URL using the controller method's variable names. Since PHP does not support type hints for primitive types such as ints and booleans, we need to add them as annotations in the comments. In order to type cast a parameter to an int, add **@param int $parameterName**
192
-
193
171
Now the controller methods need to be connected to the corresponding URLs in the **notestutorial/appinfo/routes.php** file:
194
172
195
173
.. code-block:: php
@@ -225,8 +203,8 @@ Database
225
203
226
204
Now that the routes are set up and connected the notes should be saved in the
227
205
database. To do that first create a :doc:`database migration <../basics/storage/migrations>`
228
-
by creating a file **notestutorial/lib/Migration/VersionXXYYZZDateYYYYMMDDHHSSAA.php**,
229
-
so for example **notestutorial/lib/Migration/Version000000Date20181013124731.php**""
206
+
by creating a file ``notestutorial/lib/Migration/VersionXYYYDateYYYYMMDDHHSSAA.php``,
207
+
so for example version 1.4.3 goes with ``notestutorial/lib/Migration/Version1004Date20181013124731.php``
230
208
231
209
.. code-block:: php
232
210
@@ -239,7 +217,7 @@ so for example **notestutorial/lib/Migration/Version000000Date20181013124731.php
239
217
use OCP\Migration\SimpleMigrationStep;
240
218
use OCP\Migration\IOutput;
241
219
242
-
class Version1400Date20181013124731 extends SimpleMigrationStep {
220
+
class Version1004Date20181013124731 extends SimpleMigrationStep {
243
221
244
222
/**
245
223
* @param IOutput $output
@@ -281,7 +259,7 @@ To create the tables in the database, run the :ref:`migration <migration_consol
.. note:: To trigger the table creation/alteration when user updating the app, update the :doc:`version tag <info>` in **notestutorial/appinfo/info.xml** . migration will be executed when user reload page after app upgrade
287
265
@@ -400,6 +378,7 @@ You can pass in the mapper by adding it as a type hinted parameter. Nextcloud wi
400
378
401
379
use OCP\IRequest;
402
380
use OCP\AppFramework\Http;
381
+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
403
382
use OCP\AppFramework\Http\DataResponse;
404
383
use OCP\AppFramework\Controller;
405
384
@@ -417,18 +396,12 @@ You can pass in the mapper by adding it as a type hinted parameter. Nextcloud wi
417
396
$this->userId = $userId;
418
397
}
419
398
420
-
/**
421
-
* @NoAdminRequired
422
-
*/
399
+
#[NoAdminRequired]
423
400
public function index(): DataResponse {
424
401
return new DataResponse($this->mapper->findAll($this->userId));
425
402
}
426
403
427
-
/**
428
-
* @NoAdminRequired
429
-
*
430
-
* @param int $id
431
-
*/
404
+
#[NoAdminRequired]
432
405
public function show(int $id): DataResponse {
433
406
try {
434
407
return new DataResponse($this->mapper->find($id, $this->userId));
@@ -437,12 +410,7 @@ You can pass in the mapper by adding it as a type hinted parameter. Nextcloud wi
437
410
}
438
411
}
439
412
440
-
/**
441
-
* @NoAdminRequired
442
-
*
443
-
* @param string $title
444
-
* @param string $content
445
-
*/
413
+
#[NoAdminRequired]
446
414
public function create(string $title, string $content): DataResponse {
447
415
$note = new Note();
448
416
$note->setTitle($title);
@@ -451,13 +419,7 @@ You can pass in the mapper by adding it as a type hinted parameter. Nextcloud wi
451
419
return new DataResponse($this->mapper->insert($note));
452
420
}
453
421
454
-
/**
455
-
* @NoAdminRequired
456
-
*
457
-
* @param int $id
458
-
* @param string $title
459
-
* @param string $content
460
-
*/
422
+
#[NoAdminRequired]
461
423
public function update(int $id, string $title, string $content): DataResponse {
462
424
try {
463
425
$note = $this->mapper->find($id, $this->userId);
@@ -469,11 +431,7 @@ You can pass in the mapper by adding it as a type hinted parameter. Nextcloud wi
469
431
return new DataResponse($this->mapper->update($note));
470
432
}
471
433
472
-
/**
473
-
* @NoAdminRequired
474
-
*
475
-
* @param int $id
476
-
*/
434
+
#[NoAdminRequired]
477
435
public function destroy(int $id): DataResponse {
478
436
try {
479
437
$note = $this->mapper->find($id, $this->userId);
@@ -645,6 +603,7 @@ Now we can wire up the trait and the service inside the **NoteController**:
645
603
namespace OCA\NotesTutorial\Controller;
646
604
647
605
use OCP\IRequest;
606
+
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
648
607
use OCP\AppFramework\Http\DataResponse;
649
608
use OCP\AppFramework\Controller;
650
609
@@ -664,52 +623,31 @@ Now we can wire up the trait and the service inside the **NoteController**:
664
623
$this->userId = $userId;
665
624
}
666
625
667
-
/**
668
-
* @NoAdminRequired
669
-
*/
626
+
#[NoAdminRequired]
670
627
public function index(): DataResponse {
671
628
return new DataResponse($this->service->findAll($this->userId));
672
629
}
673
630
674
-
/**
675
-
* @NoAdminRequired
676
-
*
677
-
* @param int $id
678
-
*/
631
+
#[NoAdminRequired]
679
632
public function show(int $id): DataResponse {
680
633
return $this->handleNotFound(function () use ($id) {
681
634
return $this->service->find($id, $this->userId);
682
635
});
683
636
}
684
637
685
-
/**
686
-
* @NoAdminRequired
687
-
*
688
-
* @param string $title
689
-
* @param string $content
690
-
*/
638
+
#[NoAdminRequired]
691
639
public function create(string $title, string $content) {
0 commit comments