1. Go to this page and download the library: Download zfr/zfr-prerender library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use ZfrPrerender\Mvc\PrerenderEvent;
public function onBootstrap(MvcEvent $event)
{
$eventManager = $event->getTarget()->getEventManager();
$sharedManager = $eventManager->getSharedManager();
$sharedManager->attach(
'ZfrPrerender\Mvc\PrerenderListener',
PrerenderEvent::EVENT_PRERENDER_PRE,
array($this, 'prerenderPre')
);
$sharedManager->attach(
'ZfrPrerender\Mvc\PrerenderListener',
PrerenderEvent::EVENT_PRERENDER_POST,
array($this, 'prerenderPost')
);
}
public function prerenderPre(PrerenderEvent $event)
{
$request = $event->getRequest();
// Check from your cache if you have already the content
// $content = ...
$response = new Response();
$response->setStatusCode(200);
$response->setContent($content);
return $response;
}
public function prerenderPost(PrerenderEvent $event)
{
// This is the response we get from the Prerender service
$response = $event->getResponse();
// You could get the body and put it in cache
// ...
}
sh
$ php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.