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: docs/controllers.md
+20-1Lines changed: 20 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -310,7 +310,26 @@ class InvoicesController extends Controller
310
310
The above parameters will match the route the way it was defined.
311
311
312
312
## Events
313
-
Controllers automatically act as listeners for [dispatcher][dispatcher][events][events], implementing methods with those event names allowing you to implement hook points before/after the actions are executed:
313
+
Controllers automatically act as listeners for [dispatcher][dispatcher][events][events], implementing methods with those event names allowing you to implement hook points before/after the actions are executed.
314
+
315
+
Controllers also implement `Phalcon\Events\EventsAwareInterface`, which means you can attach an events manager directly to any controller instance using `setEventsManager()` and retrieve it with `getEventsManager()`:
316
+
317
+
```php
318
+
<?php
319
+
320
+
use Phalcon\Events\Manager;
321
+
use Phalcon\Mvc\Controller;
322
+
323
+
$controller = new InvoicesController();
324
+
325
+
$eventsManager = new Manager();
326
+
$eventsManager->attach('controller', function ($event, $controller) {
Copy file name to clipboardExpand all lines: docs/db-models.md
+41-1Lines changed: 41 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2332,6 +2332,24 @@ Phalcon's resultsets emulate scrollable cursors. You can get any row just by acc
2332
2332
2333
2333
Storing large query results in memory will consume many resources. You can however instruct Phalcon to fetch data in chunks of rows, thus reducing the need to re-execute the request in many cases. You can achieve that by setting the `orm.resultset_prefetch_records` setup value. This can be done either in `php.ini` or in the model `setup()`. More information about this can be found in the [features](#model-features) section.
2334
2334
2335
+
You can re-execute the underlying query at any time to update the resultset with fresh data from the database by calling `refresh()`. This is useful in long-running scripts or when you suspect the data may have changed since the resultset was last loaded.
// ... time passes, other processes may have inserted rows ...
2347
+
2348
+
$invoices->refresh();
2349
+
2350
+
echo count($invoices); // updated count
2351
+
```
2352
+
2335
2353
Note that resultsets can be serialized and stored in a cache backend. [Phalcon\Cache\Cache][cache] can help with that task. However, serializing data causes [Phalcon\Mvc\Model][mvc-model] to retrieve all the data from the database in an array, thus consuming more memory while this process takes place.
2336
2354
2337
2355
```php
@@ -3820,7 +3838,7 @@ class Invoices extends Model
3820
3838
```
3821
3839
3822
3840
## Model Features
3823
-
The ORM has several options that control specific behaviors globally. You can enable or disable these features by adding specific lines to your `php.ini` file or using the `setup` static method on the model. You can enable or disable these features temporarily in your code or permanently.
3841
+
The ORM has several options that control specific behaviors globally. You can enable or disable these features by adding specific lines to your `php.ini` file, using the `setup` static method on the model, or using `Phalcon\Support\Settings` for a PHP-level override that does not call `ini_set()`.
3824
3842
3825
3843
```ini
3826
3844
phalcon.orm.column_renaming = false
@@ -3890,6 +3908,28 @@ The available options are:
3890
3908
; phalcon.db.force_casting = Off
3891
3909
```
3892
3910
3911
+
**Using `Phalcon\Support\Settings`**
3912
+
3913
+
`Phalcon\Support\Settings` provides PHP-level overrides for all framework settings. Unlike `ini_set()`, changes made with `Settings::set()` are stored in a static array and never modify the underlying `php.ini` configuration, which prevents settings from one project from leaking into another sharing the same PHP process.
3914
+
3915
+
```php
3916
+
<?php
3917
+
3918
+
use Phalcon\Support\Settings;
3919
+
3920
+
// Override a setting at the PHP level
3921
+
Settings::set('orm.column_renaming', false);
3922
+
Settings::set('orm.events', false);
3923
+
3924
+
// Read the effective value (PHP override → php.ini → compiled default)
// Clear all PHP-level overrides and revert to php.ini / compiled defaults
3928
+
Settings::reset();
3929
+
```
3930
+
3931
+
The `get()` method follows this resolution order: PHP-level override → `ini_get('phalcon.<key>')` → compiled-in default.
3932
+
3893
3933
!!! warning "WARNING"
3894
3934
3895
3935
`Phalcon\Mvc\Model::assign()` (which is used also when creating/updating/saving model) is always using setters if they exist when data arguments are passed, even when it's required or necessary. This will add some additional overhead to your application. You can change this behavior by adding `phalcon.orm.disable_assign_setters = 1` to your ini file, it will just simply use `$this->property = value`.
[Phalcon\Encryption\Security\Uuid][security-uuid] is a factory that generates UUIDs (Universally Unique Identifiers) for versions 1 through 7 as defined by [RFC 4122][rfc-4122] and [RFC 9562][rfc-9562]. Each version adapter is instantiated once and cached for reuse.
483
+
484
+
### Namespace Constants
485
+
[Phalcon\Encryption\Security\Uuid\UuidInterface][security-uuid-interface] defines the four standard RFC 4122 namespace UUIDs as constants:
// always produces the same UUID for the same input
549
+
550
+
// Version 6 - reordered time-based (lexicographically sortable)
551
+
echo $uuid->v6();
552
+
553
+
// Version 7 - Unix ms timestamp + random (lexicographically sortable)
554
+
echo $uuid->v7();
555
+
```
556
+
557
+
Because each adapter is instantiated lazily and cached, repeated calls to the same `v*()` method reuse the same adapter instance.
558
+
559
+
```php
560
+
<?php
561
+
562
+
use Phalcon\Encryption\Security\Uuid;
563
+
564
+
$uuid = new Uuid();
565
+
566
+
// The v4 adapter is created once and reused
567
+
$id1 = $uuid->v4();
568
+
$id2 = $uuid->v4();
569
+
```
570
+
481
571
## Dependency Injection
482
572
If you use the [Phalcon\Di\FactoryDefault][factorydefault] container, the [Phalcon\Encryption\Security][security] is already registered for you. However, you might want to override the default registration in order to set your own `workFactor()`. Alternatively, if you are not using the [Phalcon\Di\FactoryDefault][factorydefault] and instead are using the [Phalcon\Di\Di][di] the registration is the same. By doing so, you will be able to access your configuration object from controllers, models, views, and any component that implements `Injectable`.
483
573
@@ -547,10 +637,13 @@ Also in your views (Volt syntax)
Copy file name to clipboardExpand all lines: docs/filter-validation.md
+49-4Lines changed: 49 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,10 +80,11 @@ Appends a message to the messages list
80
80
```php
81
81
public function bind(
82
82
object $entity,
83
-
array | object $$data
83
+
array | object $data,
84
+
array $whitelist = []
84
85
): ValidationInterface
85
86
```
86
-
Assigns the data to an entity. The entity is used to obtain the validation values
87
+
Assigns the data to an entity. The entity is used to obtain the validation values. When `$whitelist` is supplied, only the fields listed in it will be assigned to the entity; all other fields are skipped.
87
88
88
89
```php
89
90
public function getEntity(): object
@@ -173,16 +174,35 @@ Adds labels for fields
173
174
```php
174
175
public function validate(
175
176
array | object $data = null,
176
-
object $entity = null
177
+
object $entity = null,
178
+
array $whitelist = []
177
179
): Messages
178
180
```
179
-
Validate a set of data according to a set of rules
181
+
Validate a set of data according to a set of rules. When `$whitelist` is supplied, only the listed fields are bound to `$entity`; validation itself still runs over all configured fields.
180
182
181
183
```php
182
184
public function fails(): bool
183
185
```
184
186
Verify if the validation has failed or not. Returns `true` when validation fails, `false` when validation succeeds.
185
187
188
+
```php
189
+
<?php
190
+
191
+
use Phalcon\Filter\Validation;
192
+
use Phalcon\Filter\Validation\Validator\PresenceOf;
193
+
194
+
$validation = new Validation();
195
+
$validation->add('name', new PresenceOf(['message' => 'Name is required']));
196
+
197
+
$validation->validate(['name' => '']);
198
+
199
+
if ($validation->fails()) {
200
+
foreach ($validation->getMessages() as $message) {
201
+
echo $message, PHP_EOL;
202
+
}
203
+
}
204
+
```
205
+
186
206
## Activation
187
207
Validation chains can be initialized in a direct manner by just adding validators to the [Phalcon\Filter\Validation][validation] object. You can put your validations in a separate file for better code reuse and organization.
188
208
@@ -1876,6 +1896,31 @@ if (count($messages)) {
1876
1896
}
1877
1897
```
1878
1898
1899
+
## Whitelist
1900
+
When validating data that will be applied to an entity (e.g. a model), you can restrict which fields are assigned to the entity by passing a `$whitelist` array. Only the fields listed in the whitelist will be bound; all other incoming fields are ignored. Validators still run over all configured fields regardless of the whitelist.
1901
+
1902
+
```php
1903
+
<?php
1904
+
1905
+
use Phalcon\Filter\Validation;
1906
+
use Phalcon\Filter\Validation\Validator\PresenceOf;
1907
+
1908
+
$validation = new Validation();
1909
+
1910
+
$validation->add('name', new PresenceOf(['message' => 'Name is required']));
1911
+
$validation->add('email', new PresenceOf(['message' => 'Email is required']));
1912
+
$validation->add('role', new PresenceOf(['message' => 'Role is required']));
1913
+
1914
+
$entity = new stdClass();
1915
+
1916
+
// Only 'name' and 'email' are assigned to $entity even though 'role' is in the data
0 commit comments