PHP code example of skeeks / yii2-dadata-suggest-api

1. Go to this page and download the library: Download skeeks/yii2-dadata-suggest-api 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/ */

    

skeeks / yii2-dadata-suggest-api example snippets


//App config
[
    'components'    =>
    [
    //....
        'dadataSuggestApi' =>
        [
            'class'                 => 'skeeks\yii2\dadataSuggestApi\DadataSuggestApi',
            'authorization_token'   => 'token',
            'timeout'               => 12,
        ],
    //....
    ]
]


$response = \Yii::$app->dadataSuggestApi->send('/rs/suggest/address', [
    'query' => 'Хабар',
    'count' => 10
]);

print_r($response->httpClientRequest->url);     //Full api url
print_r($response->httpClientRequest->data);    //Request data
print_r($response->httpClientRequest->method);  //Request method
print_r($response->httpClientRequest->headers); //Request headers

print_r($response->httpClientResponse->statusCode); //Server response code
print_r($response->httpClientResponse->content);    //Original api response

if ($response->isError)
{
    print_r($response->errorMessage); //Расшифровка кода
    print_r($response->errorData);
    print_r($response->errorCode);
} else
{
    print_r($response->data); //Array response data
}

$response = \Yii::$app->dadataSuggestApi->detectAddressByIp(\Yii::$app->request->userIP);

$response = \Yii::$app->dadataSuggestApi->getEmail([
    'query' => 'info@',
    'count' => 10
]);

$response = \Yii::$app->dadataSuggestApi->getFio([
    'query' => 'Семен',
    'count' => 10
]);

php composer.phar