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
Copy file name to clipboardExpand all lines: cs/form-presenter.texy
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -234,6 +234,20 @@ class RegistrationFormData
234
234
}
235
235
```
236
236
237
+
Od PHP 8.0 můžete použít tento elegantní zápis, který využívá konstruktor:
238
+
239
+
```php
240
+
class RegistrationFormData
241
+
{
242
+
public function __construct(
243
+
public string $name,
244
+
public int $age,
245
+
public string $password,
246
+
) {
247
+
}
248
+
}
249
+
```
250
+
237
251
Jak říci Nette, aby nám data vracel jako objekty této třídy? Snadněji než si myslíte. Stačí pouze třídu uvést jako typ parametru `$data` v obslužné metodě:
Copy file name to clipboardExpand all lines: cs/form-standalone.texy
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -217,6 +217,20 @@ class RegistrationFormData
217
217
}
218
218
```
219
219
220
+
Od PHP 8.0 můžete použít tento elegantní zápis, který využívá konstruktor:
221
+
222
+
```php
223
+
class RegistrationFormData
224
+
{
225
+
public function __construct(
226
+
public string $name,
227
+
public int $age,
228
+
public string $password,
229
+
) {
230
+
}
231
+
}
232
+
```
233
+
220
234
Jak říci Nette, aby nám data vracel jako objekty této třídy? Snadněji než si myslíte. Stačí pouze název třídy nebo objekt k hydrataci uvést jako parametr:
Copy file name to clipboardExpand all lines: en/form-presenter.texy
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -234,6 +234,20 @@ class RegistrationFormData
234
234
}
235
235
```
236
236
237
+
As of PHP 8.0, you can use this elegant notation that uses a constructor:
238
+
239
+
```php
240
+
class RegistrationFormData
241
+
{
242
+
public function __construct(
243
+
public string $name,
244
+
public int $age,
245
+
public string $password,
246
+
) {
247
+
}
248
+
}
249
+
```
250
+
237
251
How to tell Nette to return data as objects of this class? Easier than you think. All you have to do is specify the class as the type of the `$data` parameter in the handler:
Copy file name to clipboardExpand all lines: en/form-standalone.texy
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -217,6 +217,20 @@ class RegistrationFormData
217
217
}
218
218
```
219
219
220
+
As of PHP 8.0, you can use this elegant notation that uses a constructor:
221
+
222
+
```php
223
+
class RegistrationFormData
224
+
{
225
+
public function __construct(
226
+
public string $name,
227
+
public int $age,
228
+
public string $password,
229
+
) {
230
+
}
231
+
}
232
+
```
233
+
220
234
How to tell Nette to return data to us as objects of this class? Easier than you think. All you have to do is specify the class name or object to hydrate as a parameter:
0 commit comments