Hi
Me again with my API, I’m trying now to create virtual pages, and I have followed the guide from virtual pages with
review.php
, reviews.php
template and this is my reviews.php
model :
class ReviewsPage extends Page
{
public function children()
{
if ($this->children instanceof Pages) {
return $this->children;
}
$results = [];
$pages = [];
$request = Remote::get('https://api.urlapi.fr/36/artworks/');
if ($request->code() === 200) {
$results = $request->json();
}
foreach ($results["results"] as $key => $review) {
$pages[] = [
'slug' => Str::slug($review["_source"]["ua"]["artwork"]["authors_notice"]),
'num' => $key+1,
'template' => 'review',
'model' => 'review',
'content' => [
'title' => $review["_source"]["ua"]["artwork"]["authors_notice"],
'uuid' => Uuid::generate(),
]
];
}
return $this->children = Pages::factory($pages, $this);
}
}
But when I’m on my reviews.php template, I don’t get any children with
<?php foreach ($page->children() as $review): ?>
<li>
<h2><?= $review->title() ?></h2>
<a href="<?= $review->url() ?>">Read review summary</a>
</li>
<?php endforeach ?>
I’m working with a JSON array here, but I don’t know how to check if the response is correct or not and where to find the childrens from the array I’m calling ?