PHP code example of district5 / formatter

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

    

district5 / formatter example snippets


// single object for format
$formatted = MyFormatter::formatSingle($model);

// multiple objects for format
$formatted = MyFormatter::formatMultiple($models);

use District5\Formatter\FormatterAbstract;

class MyFormatter extends FormatterAbstract
{
    public static function formatSingle($item, array $options = null)
    {
        return [
            'field1' => 'someValue',
            'field2' => 5
        ];
    }
}

use District5\Formatter\FormatterAbstract;

class MyComplexFormatter extends FormatterAbstract
{
    public static function formatSingle($item, array $options = null)
    {
        $formatted = array(
            'id' => $item->getIdStr(),
            'created' => $item->getCreatedDateMillis(),
            'title' => $item->getTitle(),
            'text' => $item->getText()
        );
        
        if (false !== static::getOption('

// single object for format
$formatted = MyComplexFormatter::formatSingle(
    $model,
    [
        ',
    [
        '