I am completely new in Magento and trying to create a widget that will simply display the selected pages on the frontend.
That's what I have for now in my block class:
public function getPages() {
// 'selectedpages' is a string with page identifiers: 'no-route','cookie-consent',...
$selectedPages = explode(',', $this->getData('selectedpages'));
$pages = array();
foreach($selectedPages as $singleSelectedPage) {
// Adding a filter
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('identifier', $singleSelectedPage)
->create()
// Putting all the results into array;
$pages[] = $this->pageRepositoryInterface->getList($searchCriteria)->getItems();
}
return $pages;
}
In my template:
<?php foreach($block->getPages() as $pageItem) : ?>
<?php echo $pageItem ?>
<?php endforeach; ?>
The problem is that once I call for the $pages[]
array somehow, it throws me a 500 error stating that Allowed memory size of 2147483648 bytes exhausted (tried to allocate 1474314240 bytes)
.
My memory limits are set to 2G - in nginx configuration, as well as in php.ini, .user.ini, /pub/.user.ini and in all .htaccess (yeah, I know that nginx won't listen to .htaccess).
Doing memory_usage()
shows that I am using only about 12Mb BEFORE calling this array.
Update: Converting $pages[]
to $pages
solves the problem, but only displays the last page, since this all is inside of the foreach
loop.
Where the problem may be?
Kind regards