PHP code example of antons / switchfield

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

    

antons / switchfield example snippets


class MyDataObject extends DataObject {

	private static $db = array(
		'Switch' => 'Boolean'
	);

	public function getCMSFields() {
		$fields = parent::getCMSFields();
		
		// Create the SwitchField
		$switch = SwitchField::create('Switch', 'Switch', $this->Switch);
		
		$fields->addFieldToTab('Root.Main', $switch);
	
		return $fields;
	}

}