Skip to content

Commit f085d71

Browse files
committed
docs(README): Add data access patterns section to SDK documentation
- Introduced a new section detailing data access patterns using object notation and array access. - Provided examples for accessing properties of Page, Site, Contentlet, and Container classes. - Clarified which classes support object notation, array access, or both.
1 parent 9693307 commit f085d71

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,74 @@ These utilities help with common tasks like:
339339
- Working with container structures and contentlets
340340
- Extracting data from container pages
341341

342+
## Data Access Patterns
343+
344+
The SDK provides two ways to access data: object notation and array access. Here's when to use each:
345+
346+
### Object Notation (->)
347+
348+
Use object notation for accessing standard properties of these classes:
349+
350+
```php
351+
// Page and Site properties
352+
$page->title
353+
$page->pageUrl
354+
$site->hostname
355+
356+
// Container properties
357+
$container->identifier
358+
$container->title
359+
$container->maxContentlets
360+
361+
// Contentlet properties
362+
$contentlet->identifier
363+
$contentlet->title
364+
$contentlet->contentType
365+
366+
// Navigation properties
367+
$nav->title
368+
$nav->href
369+
$nav->type
370+
```
371+
372+
### Array Access ([])
373+
374+
Use array access for:
375+
1. Additional properties not explicitly defined in the class
376+
2. Accessing container contentlets by UUID
377+
3. Accessing rendered content by UUID
378+
379+
```php
380+
// Additional properties
381+
$contentlet['customField']
382+
$page['metadata']
383+
384+
// Container contentlets
385+
$container->contentlets['uuid-123']
386+
387+
// Rendered content
388+
$container->rendered['uuid-123']
389+
```
390+
391+
### Classes That Support Both
392+
393+
These classes support both object and array access:
394+
- `Page`
395+
- `Site`
396+
- `Contentlet`
397+
- `Container`
398+
- Any class extending `AbstractModel`
399+
400+
### Classes That Only Support Object Access
401+
402+
These classes only support object notation:
403+
- `PageAsset`
404+
- `ContainerPage`
405+
- `NavigationItem`
406+
- `Layout`
407+
- `Template`
408+
- `VanityUrl`
409+
342410
## API Reference
343411

344412
### DotCMSClient

0 commit comments

Comments
 (0)