PHP code example of cathedral / db

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

    

cathedral / db example snippets


/**
 * Gets the query string parameters for pagination
 *
 * @param array $options
 * @param array $params
 *
 * @return void
 */
public function customQueryOptions(&$options, $params): void {
    if (isset($params['fk_champions'])) $options['where']['fk_champions'] = intval($params['fk_champions']);
}

/**
 * Gets the query string parameters for pagination
 *
 * @param mixed $json
 * @return void
 */
public function customResponseOptions(&$json): void {
    /** @var JsonModel $json */
    $payload = $json->getVariable('payload');

    for ($i = 0; $i < \count($payload); $i++) $payload[$i]['champion'] = $this->_champions[$payload[$i]['fk_champions']];

    $json->setVariable('extra', ['champions' => $this->_champions]);
    $json->setVariable('payload', $payload);
}

/**
 * Modify the resultset
 *
 * @param mixed $data
 * @return void
 */
public function getListPost($data): void {
    $data->buffer();
    foreach($data as $d) $this->_champions[$d->Champion()->id] = $d->Champion()->name;
}

/**
 * Check data before creating record
 *
 * @param mixed $data
 * @return null|string error
 */
public function createPre(&$data): ?string {
    // check data
    return null;
}