PHP code example of s1njar / igdb

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

    

s1njar / igdb example snippets


//Create new SearchBuilder object.
$searchBuilder = new SearchBuilder($apiKey);

//Add the endpoint to be requested.
$searchBuilder = $searchBuilder->addEndpoint('games');

//Add the fields you want to return.
$searchBuilder = $searchBuilder->addFields(['id', 'name']);

//Add multiple filters to refine the search.
$searchBuilder = $searchBuilder->addFilter('rating', '=', '75');

//Add multiple filters to refine multi filter search.
$searchBuilder = $searchBuilder->addFilter('platforms', '=', (1,2,3));

//Add a limit.
$searchBuilder = $searchBuilder->addLimit('10');

//Add an offset.
$searchBuilder = $searchBuilder->addOffset('0');

//Add an order.
$searchBuilder = $searchBuilder->addOrder('popularity', 'desc');

//Trigger the search. It returns an Response object.
$searchBuilder = $searchBuilder->search();

//Decode the response from the server and return an array of objects.
$response = $searchBuilder->get();

//Create new SearchBuilder object.
$searchBuilder = new SearchBuilder($apiKey);

//Add endpoint and search by id.
$response = $searchBuilder
    ->addEndpoint('games')
    ->searchById(1, ['name', 'id'])
    ->get();

//Create new SearchBuilder object.
$searchBuilder = new SearchBuilder($apiKey);

//Add endpoint, fields and search needle.
$response = $searchBuilder
    ->addEndpoint('games')
    ->addFields(['id'])
    ->addSearch('witcher')
    ->search()
    ->get();

[
    0 => {
        'id' => '1',
        'name' => 'Witcher'
    },
    1 => {
        'id' => '2',
        'name' => 'Fallout'
    }
]