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: en/00_Getting_Started/02_Composer.md
+32-38
Original file line number
Diff line number
Diff line change
@@ -22,9 +22,8 @@ installed globally. You should now be able to run the command:
22
22
composer help
23
23
```
24
24
25
-
[info]
26
-
If you already have Composer installed, make sure it is composer 2 by running `composer --version`. If you're running Composer 1, run [`composer self-update`](https://getcomposer.org/doc/03-cli.md#self-update-selfupdate). You may also want to check out the [upgrade guide for Composer 1.x to 2.0](https://getcomposer.org/upgrade/UPGRADE-2.0.md).
27
-
[/info]
25
+
> [!NOTE]
26
+
> If you already have Composer installed, make sure it is composer 2 by running `composer --version`. If you're running Composer 1, run [`composer self-update`](https://getcomposer.org/doc/03-cli.md#self-update-selfupdate). You may also want to check out the [upgrade guide for Composer 1.x to 2.0](https://getcomposer.org/upgrade/UPGRADE-2.0.md).
Individual settings can be assigned via [`Environment::setEnv()`](api:SilverStripe\Core\Environment::setEnv()) or [`Environment::putEnv()`](api:SilverStripe\Core\Environment::putEnv()) methods.
64
63
@@ -67,9 +66,8 @@ use SilverStripe\Core\Environment;
`Environment::getEnv()` will return `false` whether the variable was explicitly set as `false` or simply wasn't set at all. You can use [`Environment::hasEnv()`](api:SilverStripe\Core\Environment::hasEnv()) to check whether an environment variable was set or not.
72
-
[/warning]
69
+
> [!WARNING]
70
+
> `Environment::getEnv()` will return `false` whether the variable was explicitly set as `false` or simply wasn't set at all. You can use [`Environment::hasEnv()`](api:SilverStripe\Core\Environment::hasEnv()) to check whether an environment variable was set or not.
73
71
74
72
### Using environment variables in config
75
73
@@ -91,9 +89,8 @@ $loader = new EnvironmentLoader();
91
89
$loader->loadFile($env);
92
90
```
93
91
94
-
[warning]
95
-
Note that because `_config.php` is processed after YAML configuration, variables set in these extra `.env` files cannot be used inside YAML config.
96
-
[/warning]
92
+
> [!WARNING]
93
+
> Note that because `_config.php` is processed after YAML configuration, variables set in these extra `.env` files cannot be used inside YAML config.
Copy file name to clipboardExpand all lines: en/00_Getting_Started/index.md
+2-3
Original file line number
Diff line number
Diff line change
@@ -29,9 +29,8 @@ Within the newly created `my-project` folder, point your webserver at the `publi
29
29
30
30
Now create a `.env` file in your project root (not the `public/` folder).
31
31
32
-
[hint]
33
-
If you used `silverstripe/installer` to create your project, you can rename the `.env.example` file to `.env`. It includes the minimum required [environment variables](environment_management).
34
-
[/hint]
32
+
> [!TIP]
33
+
> If you used `silverstripe/installer` to create your project, you can rename the `.env.example` file to `.env`. It includes the minimum required [environment variables](environment_management).
Copy file name to clipboardExpand all lines: en/02_Developer_Guides/00_Model/01_Data_Model_and_ORM.md
+35-48
Original file line number
Diff line number
Diff line change
@@ -43,21 +43,19 @@ class Player extends DataObject
43
43
This `Player` class definition will create a database table `Player` with columns for `PlayerNumber`, `FirstName` and
44
44
so on. After writing this class, we need to regenerate the database schema.
45
45
46
-
[hint]
47
-
You can technically omit the `table_name` property, and a default table name will be created based on the fully qualified class name - but this can result in table names that are too long for the database engine to handle. We recommend that you *always* explicitly declare a table name for your models.
48
-
49
-
See more in [Mapping classes to tables with `DataObjectSchema`](#mapping-classes-to-tables) below.
50
-
[/hint]
46
+
> [!TIP]
47
+
> You can technically omit the `table_name` property, and a default table name will be created based on the fully qualified class name - but this can result in table names that are too long for the database engine to handle. We recommend that you *always* explicitly declare a table name for your models.
48
+
>
49
+
> See more in [Mapping classes to tables with `DataObjectSchema`](#mapping-classes-to-tables) below.
51
50
52
51
## Generating the database schema
53
52
54
53
After adding, modifying or removing `DataObject` subclasses, make sure to rebuild your Silverstripe CMS database. The
55
54
database schema is generated automatically by visiting `/dev/build` (e.g. `https://www.example.com/dev/build`) in your browser
56
55
while authenticated as an administrator, or by running `sake dev/build` on the command line (see [Command Line Interface](/developer_guides/cli/) to learn more about `sake`).
57
56
58
-
[info]
59
-
In "dev" mode, you do not need to be authenticated to run `/dev/build`. See [Environment Types](/developer_guides/debugging/environment_types) for more information.
60
-
[/info]
57
+
> [!NOTE]
58
+
> In "dev" mode, you do not need to be authenticated to run `/dev/build`. See [Environment Types](/developer_guides/debugging/environment_types) for more information.
61
59
62
60
This script will analyze the existing schema, compare it to what's required by your data classes, and alter the schema
63
61
as required.
@@ -119,11 +117,10 @@ However, a better way is to use the `create()` method.
119
117
$player = Player::create();
120
118
```
121
119
122
-
[hint]
123
-
Using the `create()` method provides chainability (known as a "fluent API" or "[fluent interface](https://en.wikipedia.org/wiki/Fluent_interface)"), which can add elegance and brevity to your code, e.g. `Player::create(['FirstName' => 'Sam'])->write()`.
124
-
125
-
More importantly, however, it will look up the class in the [`Injector`](api:SilverStripe\Core\Injector\Injector) so that the class can be overridden by [dependency injection](../extending/injector). For this reason, instantiating records using the `new` keyword is considered bad practice.
126
-
[/hint]
120
+
> [!TIP]
121
+
> Using the `create()` method provides chainability (known as a "fluent API" or "[fluent interface](https://en.wikipedia.org/wiki/Fluent_interface)"), which can add elegance and brevity to your code, e.g. `Player::create(['FirstName' => 'Sam'])->write()`.
122
+
>
123
+
> More importantly, however, it will look up the class in the [`Injector`](api:SilverStripe\Core\Injector\Injector) so that the class can be overridden by [dependency injection](../extending/injector). For this reason, instantiating records using the `new` keyword is considered bad practice.
127
124
128
125
Database columns (aka fields) can be set as class properties on the object. The Silverstripe CMS ORM handles the saving
129
126
of the values through a custom `__set()` method.
@@ -152,6 +149,9 @@ $id = $player->write();
152
149
With the `Player` class defined we can query our data using the ORM. The ORM provides
153
150
shortcuts and methods for fetching, sorting and filtering data from our database.
154
151
152
+
> [!TIP]
153
+
> All of the below methods to get a single record will return `null` if there is no record to return.
154
+
155
155
```php
156
156
// returns a `DataList` containing all the `Player` objects.
All of the above methods to get a single record will return `null` if there is no record to return.
170
-
[/hint]
171
-
172
-
[info]
173
-
`DataObject::get()->byID()` and `DataObject::get_by_id()` achieve similar results, though the object returned by `DataObject::get_by_id()` is cached against a `static` property within `DataObject`.
174
-
[/info]
168
+
> [!NOTE]
169
+
> `DataObject::get()->byID()` and `DataObject::get_by_id()` achieve similar results, though the object returned by `DataObject::get_by_id()` is cached against a `static` property within `DataObject`.
175
170
176
171
The ORM uses a "fluent" syntax, where you specify a query by chaining together different methods. Two common methods
There's a lot more to filtering and sorting, so make sure to keep reading.
187
182
188
-
[info]
189
-
Values passed in to the `filter()` and `sort()` methods are automatically escaped and do not require any additional escaping. This makes it easy to safely filter/sort records by user input.
190
-
[/info]
183
+
> [!NOTE]
184
+
> Values passed in to the `filter()` and `sort()` methods are automatically escaped and do not require any additional escaping. This makes it easy to safely filter/sort records by user input.
191
185
192
186
### Querying data when you have a record
193
187
194
188
When you have a `DataObject` record, it already has all of its database field data attached to it. You can get those values without triggering further database queries.
195
189
196
-
[notice]
197
-
This does not apply to relations, which are always lazy loaded. See the [Relations between Records](relations) documentation for more information.
198
-
[/notice]
190
+
> [!WARNING]
191
+
> This does not apply to relations, which are always lazy loaded. See the [Relations between Records](relations) documentation for more information.
199
192
200
193
```php
201
194
$player = Player::get()->byID(2);
@@ -215,9 +208,8 @@ All database fields have a default value format which you can retrieve by treati
215
208
216
209
The ORM doesn't actually execute the [SQLSelect](api:SilverStripe\ORM\Queries\SQLSelect) query until you iterate on the result (e.g. with a `foreach()` or `<% loop %>`).
217
210
218
-
[hint]
219
-
Some convenience methods (e.g. [`column()`](api:SilverStripe\ORM\DataList::column()) or aggregator methods like [`min()`](api:SilverStripe\ORM\DataList::min())) will also execute the query.
220
-
[/hint]
211
+
> [!TIP]
212
+
> Some convenience methods (e.g. [`column()`](api:SilverStripe\ORM\DataList::column()) or aggregator methods like [`min()`](api:SilverStripe\ORM\DataList::min())) will also execute the query.
221
213
222
214
It's smart enough to generate a single efficient query at the last moment in time without needing to post-process the
223
215
result set in PHP. In `MySQL` the query generated by the ORM may look something like this
@@ -267,9 +259,8 @@ if ($players->exists()) {
267
259
}
268
260
```
269
261
270
-
[hint]
271
-
While you could use `if ($players->Count() > 0)` for this condition, the `exists()` method uses an `EXISTS` SQL query, which is more performant.
272
-
[/hint]
262
+
> [!TIP]
263
+
> While you could use `if ($players->Count() > 0)` for this condition, the `exists()` method uses an `EXISTS` SQL query, which is more performant.
273
264
274
265
See the [Lists](lists) documentation for more information on dealing with [SS_List](api:SilverStripe\ORM\SS_List) instances.
The above examples are using "dot notation" to get the aggregations of the `Players` relation on the `Teams` model. See [Relations between Records](relations) to learn more.
459
-
[/hint]
448
+
> [!TIP]
449
+
> The above examples are using "dot notation" to get the aggregations of the `Players` relation on the `Teams` model. See [Relations between Records](relations) to learn more.
460
450
461
451
### `filterByCallback`
462
452
463
453
It is possible to filter by a PHP callback using the [`filterByCallback()`](api:SilverStripe\ORM\DataList::filterByCallback()) method. This will force the data model to fetch all records and loop them in
464
454
PHP which will be much worse for performance, thus `filter()` or `filterAny()` are to be preferred over `filterByCallback()`.
465
455
466
-
[notice]
467
-
Because `filterByCallback()` has to run in PHP, it has a significant performance tradeoff, and should not be used on large recordsets.
468
-
469
-
`filterByCallback()` will always return an `ArrayList`.
470
-
[/notice]
456
+
> [!WARNING]
457
+
> Because `filterByCallback()` has to run in PHP, it has a significant performance tradeoff, and should not be used on large recordsets.
458
+
>
459
+
> `filterByCallback()` will always return an `ArrayList`.
471
460
472
461
The first parameter to the callback is the record, the second parameter is the list itself. The callback will run once
473
462
for each record. The callback must return a boolean value. If the callback returns true, the current record will be included in the list of returned items.
Using a join will *filter* results further by the JOINs performed against the foreign table. It will
688
-
**not return** the additionally joined data. For the examples above, we're still only selecting values for the fields
689
-
on the `Member` class table.
690
-
[/alert]
675
+
> [!CAUTION]
676
+
> Using a join will *filter* results further by the JOINs performed against the foreign table. It will
677
+
> **not return** the additionally joined data. For the examples above, we're still only selecting values for the fields
678
+
> on the `Member` class table.
691
679
692
680
### Default values
693
681
@@ -769,9 +757,8 @@ Product_Digital_Computer:
769
757
IsPreBuilt: 'Boolean'
770
758
```
771
759
772
-
[hint]
773
-
Note that because `DigitalProduct` doesn't define any new fields it doesn't need its own table. We should still declare a `$table_name` though - who knows if this model might have its own table created in the future (e.g. if we add fields to it later on).
774
-
[/hint]
760
+
> [!TIP]
761
+
> Note that because `DigitalProduct` doesn't define any new fields it doesn't need its own table. We should still declare a `$table_name` though - who knows if this model might have its own table created in the future (e.g. if we add fields to it later on).
775
762
776
763
Accessing the data is transparent to the developer.
0 commit comments