PHP code example of davidyell / listing

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

    

davidyell / listing example snippets


array(
    1 => 'First',
    2 => 'Second'
);

array(
    'Cats' => array(
        1 => 'First',
    ),
    'Dogs' => array(
        2 => 'Second'
    )
);

public $actsAs = array(
    'Listing.Listable' => array(
       'relatedModelName' => 'Provider', // Example - this should be the parent model, the one you want to group by
       'relatedModelPrimaryKey' => 'id', // optional - default shown
       'relatedModelDisplayField' => 'name', // optional - default shown
    )
);


// app/Model/User.php
public $virtualFields = [
    'full_name' => 'CONCAT(User.first_name, ' ', User.last_name)'
];

// app/Controller/UsersController.php
$users = $this->User->find('listing', ['fields' => ['id', 'full_name']]);