9090}
9191```
9292
93+ ### Fetching Navigation
94+
95+ ``` php
96+ try {
97+ // Create a navigation request
98+ $navRequest = $client->createNavigationRequest('/about-us', 2);
99+
100+ // Get the navigation
101+ $nav = $client->getNavigation($navRequest);
102+
103+ // Access navigation information
104+ echo "Navigation title: " . $nav['title'] . "\n";
105+ echo "Navigation URL: " . $nav['href'] . "\n";
106+
107+ // Access children if available
108+ if ($nav->hasChildren()) {
109+ foreach ($nav->getChildren() as $child) {
110+ echo "- " . $child['title'] . " (" . $child['href'] . ")\n";
111+ }
112+ }
113+
114+ } catch (\Exception $e) {
115+ echo "Error: " . $e->getMessage() . "\n";
116+ }
117+ ```
118+
93119### Asynchronous Requests
94120
95121``` php
@@ -113,6 +139,34 @@ $promise->then(
113139$promise->wait();
114140```
115141
142+ ### Asynchronous Navigation Requests
143+
144+ ``` php
145+ // Create a navigation request
146+ $asyncNavRequest = $client->createNavigationRequest('/', 2);
147+
148+ // Get the navigation asynchronously
149+ $promise = $client->getNavigationAsync($asyncNavRequest);
150+
151+ // Add callbacks for success and failure
152+ $promise->then(
153+ function ($nav) {
154+ echo "Navigation title: " . $nav['title'] . "\n";
155+ if ($nav->hasChildren()) {
156+ foreach ($nav->getChildren() as $child) {
157+ echo "- " . $child['title'] . "\n";
158+ }
159+ }
160+ },
161+ function (\Exception $e) {
162+ echo "Error: " . $e->getMessage() . "\n";
163+ }
164+ );
165+
166+ // Wait for the promise to complete
167+ $promise->wait();
168+ ```
169+
116170## Advanced Usage
117171
118172### Customizing Page Requests
@@ -143,6 +197,22 @@ $pageRequest = $pageRequest->withHostId('48190c8c-42c4-46af-8d1a-0cd5db894797');
143197
144198Note that each method returns a new instance with the updated value, so you need to reassign the result.
145199
200+ ### Customizing Navigation Requests
201+
202+ The ` NavigationRequest ` class allows you to customize your navigation requests:
203+
204+ ``` php
205+ // Create a navigation request with custom parameters
206+ $navRequest = $client->createNavigationRequest(
207+ path: '/about-us', // The root path to begin traversing
208+ depth: 2, // The depth of the folder tree to return (1-3)
209+ languageId: 2 // The language ID for content (e.g., 2 for Spanish)
210+ );
211+
212+ // Get the navigation with the custom parameters
213+ $nav = $client->getNavigation($navRequest);
214+ ```
215+
146216### Working with Page Components
147217
148218Once you have a page, you can access its components:
@@ -179,6 +249,43 @@ foreach ($page->containers as $containerId => $container) {
179249}
180250```
181251
252+ ### Working with Navigation Items
253+
254+ The ` NavigationItem ` class extends ` AbstractModel ` and provides array access to its properties:
255+
256+ ``` php
257+ // Check if the navigation item is a folder
258+ if ($nav->isFolder()) {
259+ echo "This is a folder\n";
260+ }
261+
262+ // Check if the navigation item is a page
263+ if ($nav->isPage()) {
264+ echo "This is a page\n";
265+ }
266+
267+ // Access navigation properties using array access
268+ echo "Title: " . $nav['title'] . "\n";
269+ echo "URL: " . $nav['href'] . "\n";
270+ echo "Type: " . $nav['type'] . "\n";
271+ echo "Target: " . $nav['target'] . "\n"; // e.g., "_self", "_blank"
272+ echo "Order: " . $nav['order'] . "\n";
273+
274+ // Recursively process navigation tree
275+ function processNavigation($navItem, $level = 0) {
276+ $indent = str_repeat(" ", $level);
277+ echo $indent . "- " . $navItem['title'] . " (" . $navItem['href'] . ")\n";
278+
279+ if ($navItem->hasChildren()) {
280+ foreach ($navItem->getChildren() as $child) {
281+ processNavigation($child, $level + 1);
282+ }
283+ }
284+ }
285+
286+ processNavigation($nav);
287+ ```
288+
182289## API Reference
183290
184291### DotCMSClient
@@ -191,6 +298,9 @@ The main client for interacting with the dotCMS API.
191298| ` getPage ` | Fetch a page synchronously | ` PageRequest $request ` |
192299| ` getPageAsync ` | Fetch a page asynchronously | ` PageRequest $request ` |
193300| ` createPageRequest ` | Create a new page request | ` string $pagePath, string $format = 'json' ` |
301+ | ` getNavigation ` | Fetch navigation items synchronously | ` NavigationRequest $request ` |
302+ | ` getNavigationAsync ` | Fetch navigation items asynchronously | ` NavigationRequest $request ` |
303+ | ` createNavigationRequest ` | Create a new navigation request | ` string $path = '/', int $depth = 1, int $languageId = 1 ` |
194304
195305### PageRequest
196306
@@ -208,6 +318,19 @@ Represents a request to the dotCMS Page API.
208318| ` buildPath ` | ** (Internal)** Build the API path for the request | None |
209319| ` buildQueryParams ` | ** (Internal)** Build the query parameters for the request | None |
210320
321+ ### NavigationRequest
322+
323+ Represents a request to the dotCMS Navigation API.
324+
325+ | Method | Description | Parameters |
326+ | --------| -------------| ------------|
327+ | ` __construct ` | Create a new navigation request | ` string $path = '/', int $depth = 1, int $languageId = 1 ` |
328+ | ` getPath ` | Get the path | None |
329+ | ` getDepth ` | Get the depth | None |
330+ | ` getLanguageId ` | Get the language ID | None |
331+ | ` buildPath ` | ** (Internal)** Build the API path for the request | None |
332+ | ` buildQueryParams ` | ** (Internal)** Build the query parameters for the request | None |
333+
211334### PageAsset
212335
213336Represents a complete page asset from dotCMS.
@@ -220,6 +343,30 @@ Represents a complete page asset from dotCMS.
220343| ` layout ` | Layout | The Layout object |
221344| ` containers ` | Array | Array of Container objects |
222345
346+ ### NavigationItem
347+
348+ Represents a navigation item from the dotCMS Navigation API. Extends AbstractModel to provide array access to properties.
349+
350+ | Property | Type | Description |
351+ | ----------| ------| -------------|
352+ | ` code ` | ?string | The code of the navigation item |
353+ | ` folder ` | ?string | The folder identifier |
354+ | ` host ` | string | The host identifier |
355+ | ` languageId ` | int | The language ID |
356+ | ` href ` | string | The URL of the navigation item |
357+ | ` title ` | string | The title of the navigation item |
358+ | ` type ` | string | The type of the navigation item (folder, htmlpage, etc.) |
359+ | ` hash ` | int | The hash of the navigation item |
360+ | ` target ` | string | The target attribute for links (_ self, _ blank, etc.) |
361+ | ` order ` | int | The order of the navigation item |
362+
363+ | Method | Description | Return Type |
364+ | --------| -------------| -------------|
365+ | ` isFolder ` | Check if this navigation item is a folder | ` bool ` |
366+ | ` isPage ` | Check if this navigation item is a page | ` bool ` |
367+ | ` hasChildren ` | Check if this navigation item has children | ` bool ` |
368+ | ` getChildren ` | Get the children as NavigationItem objects | ` ?array ` |
369+
223370## Error Handling
224371
225372The SDK provides several exception classes for error handling:
@@ -252,7 +399,7 @@ try {
252399
253400## Examples
254401
255- ### Basic Example
402+ ### Basic Page Example
256403
257404``` php
258405<?php
@@ -282,6 +429,43 @@ echo "Page title: " . $page->page->title . "\n";
282429echo "Page URL: " . $page->page->pageUrl . "\n";
283430```
284431
432+ ### Basic Navigation Example
433+
434+ ``` php
435+ <?php
436+
437+ require_once __DIR__ . '/vendor/autoload.php';
438+
439+ use Dotcms\PhpSdk\Config\Config;
440+ use Dotcms\PhpSdk\DotCMSClient;
441+
442+ // Create configuration
443+ $config = new Config(
444+ host: 'https://demo.dotcms.com',
445+ apiKey: 'YOUR_API_KEY'
446+ );
447+
448+ // Create client
449+ $client = new DotCMSClient($config);
450+
451+ // Create navigation request for the About Us section with depth=2
452+ $navRequest = $client->createNavigationRequest('/about-us', 2);
453+
454+ // Get navigation
455+ $nav = $client->getNavigation($navRequest);
456+
457+ // Display navigation information
458+ echo "Navigation title: " . $nav['title'] . "\n";
459+
460+ // Display children if available
461+ if ($nav->hasChildren()) {
462+ echo "Children:\n";
463+ foreach ($nav->getChildren() as $child) {
464+ echo "- " . $child['title'] . " (" . $child['href'] . ")\n";
465+ }
466+ }
467+ ```
468+
285469### Integration with Symfony
286470
287471The SDK can be easily integrated with Symfony. See the ` examples/dotcms-symfony ` directory for a complete example.
0 commit comments