PHP code example of heyday / silverstripe-flexibledataformatters

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

    

heyday / silverstripe-flexibledataformatters example snippets


class MyDataObject extends DataObject implements FlexibleDataFormatterInterface
{
	public static $db = array(
    	'Title' => 'Varchar(255)'
	);

    public function getReadableFields()
    {
        return array(
            'Title'
        );
    }

    public function getDynamicFields()
    {
        return array();
    }
}

$dataObject = new MyDataObject(array('Title' => 'Hello'));
$formatter = new FlexibleJsonDataFormatter();
echo $formatter->convertDataObject($dataObject);

//	Results:
//	{
//		"Title": "Hello"
//	}