PHP code example of setono / prerender-bundle
1. Go to this page and download the library: Download setono/prerender-bundle 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/ */
setono / prerender-bundle example snippets
declare(strict_types=1);
namespace App\Controller;
use Setono\PrerenderBundle\Prerenderer\PrerendererInterface;
use Symfony\Component\HttpFoundation\Response;
final class ProductController
{
public function index(PrerendererInterface $prerenderer): Response
{
if($this->isBot()) {
// return the rendered HTML if the client is a bot
return new Response($prerenderer->renderMainRequest());
}
// render the response the normal way if the client is NOT a bot
return new Response('...');
}
/**
* Method that returns true if the client is a bot
*/
private function isBot(): bool
{
// ...
}
}