-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnavigation_example.php
More file actions
66 lines (57 loc) · 2.19 KB
/
Copy pathnavigation_example.php
File metadata and controls
66 lines (57 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Dotcms\PhpSdk\Config\Config;
use Dotcms\PhpSdk\DotCMSClient;
// Create a configuration
$config = new Config(
host: 'https://demo.dotcms.com',
apiKey: 'API_KEY',
);
// Create a client
$client = new DotCMSClient($config);
// Example 1: Get top-level navigation
echo "Example 1: Top-level navigation\n";
echo "--------------------------------\n";
$navRequest = $client->createNavigationRequest('/', 1);
$nav = $client->getNavigation($navRequest);
echo "Title: " . $nav->title . "\n";
echo "URL: " . $nav->href . "\n";
echo "Type: " . $nav->type . "\n\n";
// Example 2: Get navigation with children (depth=2)
echo "Example 2: Navigation with children (depth=2)\n";
echo "------------------------------------------\n";
$navWithChildrenRequest = $client->createNavigationRequest('/application', 2);
$navWithChildren = $client->getNavigation($navWithChildrenRequest);
echo "Title: " . $navWithChildren->title . "\n";
echo "URL: " . $navWithChildren->href . "\n";
echo "Type: " . $navWithChildren->type . "\n";
if ($navWithChildren->hasChildren()) {
echo "Children:\n";
foreach ($navWithChildren->getChildren() as $child) {
echo "- " . $child->title . " (" . $child->href . ")\n";
}
}
echo "\n";
// Example 3: Get navigation in a different language
echo "Example 3: Navigation in Spanish (languageId=2)\n";
echo "-------------------------------------------\n";
$navSpanishRequest = $client->createNavigationRequest('/', 1, 2);
$navSpanish = $client->getNavigation($navSpanishRequest);
echo "Title: " . $navSpanish->title . "\n";
echo "URL: " . $navSpanish->href . "\n";
echo "Language ID: " . $navSpanish->languageId . "\n\n";
// Example 4: Async navigation request
echo "Example 4: Async navigation request\n";
echo "--------------------------------\n";
$asyncRequest = $client->createNavigationRequest('/application', 2);
$client->getNavigationAsync($asyncRequest)->then(
function ($nav) {
echo "Title: " . $nav->title . "\n";
if ($nav->hasChildren()) {
echo "Children:\n";
foreach ($nav->getChildren() as $child) {
echo "- " . $child->title . "\n";
}
}
}
)->wait();