PHP code example of silverstripe / subsites

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

    

silverstripe / subsites example snippets


Subsite::set_allowed_themes(array('blackcandy','mytheme'));

private static $has_one = [
    'Subsite' => Subsite::class
];

public function getCMSFields() {
    $fields = parent::getCMSFields();
    if (class_exists(Subsite::class)){
        $fields->push(HiddenField::create('SubsiteID', 'SubsiteID', SubsiteState::singleton()->getSubsiteId()));
    }
    return $fields;
}

public function getEditForm($id = null, $fields = null){
    $form = parent::getEditForm($id, $fields);

    $gridField = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass));
    if(class_exists(Subsite::class)){
        $list = $gridField->getList()->filter(['SubsiteID'=>SubsiteState::singleton()->getSubsiteId()]);
        $gridField->setList($list);
    }

    return $form;
}

MyAdmin::add_extension('SubsiteMenuExtension');

public function subsiteCMSShowInMenu(){
    return true;
}

$publicSubsites = DataObject::get(
    'Subsite',
    Subsite::$check_is_public ? '"IsPublic"=1' : '';
);

// Example matching subsite1.example.org and www.example.org
Session::set_cookie_domain('.example.org');