PHP code example of numero2 / contao-cookie-consent
1. Go to this page and download the library: Download numero2/contao-cookie-consent 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/ */
numero2 / contao-cookie-consent example snippets
// src/Controller/MyCustomController.php
namespace App\Controller;
use numero2\CookieConsentBundle\Util\CookieConsentUtil;
class MyCustomController
{
public function __construct(
private readonly CookieConsentUtil $cookieConsentUtil
) {}
public function __invoke(): void
{
// Returns true if the tag with ID 6 has been accepted
$this->cookieConsentUtil->isTagAccepted(6);
// Returns true if the tag with ID 6 has NOT been accepted
$this->cookieConsentUtil->isTagNotAccepted(6);
// Generates a link that triggers the consent dialog
$this->cookieConsentUtil->generateConsentForceLink();
}
}