PHP code example of syrp-nz / silverstripe-cloudlfare-purger

1. Go to this page and download the library: Download syrp-nz/silverstripe-cloudlfare-purger 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/ */

    

syrp-nz / silverstripe-cloudlfare-purger example snippets


class PromoDataObject extends DataObject {

    private static $db = [
        'SomeContent' => 'HTMLText'
    ];

    private static $has_one = [
        'Parent' => 'PromoHolderPage'
    ];

    public function Link()
    {
        // This DO can be accessed as a sub-action on the controller of its parent page through its ID.
        // If `CloudflarePurgeLinks` wasn't defined, the individual URL of this DO would be purge, but
        // not its parent.
        return $this->Parent()->Link($this->ID);
    }

    public function CloudflarePurgeLinks()
    {
        // The content of this DO is used when rendering the parent page. So when this DO is saved, we
        // want to purge the parent's page URL as well.
        return [$this->Link(), $this->Parent()->Link()];
    }

}