PHP code example of rareform / craft-prune

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

    

rareform / craft-prune example snippets


use rareform\Prune;

// Basic usage: simply pass an array of fields
$prunedData = new Prune($data, ["title", "author", "body", "url", "featuredImage"]);

// Advanced object syntax
$prunedData = new Prune($data, [
    'title' => true,
    'id' => true,
    'uri' => true,
    // Related fields simple array syntax
    'author' => ['username', 'email'],
    // Related fields object syntax
    'mainImage' => [
        'url' => true,
        'uploader' => [
            // Nested related fields
            'email' => true,
            'username' => true,
        ],
    ],
    // Matrix fields
    'contentBlocks' => [
        // Denote query traits with $ prefix
        '$limit' => 10,
        // Designate distinct prune fields per type with _ prefix
        '_body' => [
            'body' => true,
            'intro' => true,
        ],
        '_fullWidthImage' => [
            'image' => ['url', 'alt'],
        ],
    ],
]);