skeeks / yii2-dadata-suggest-api
Suggest yii2 api dadata.ru
Installs: 2 284
Dependents: 3
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Type:yii2-extension
Requires
This package is auto-updated.
Last update: 2024-11-29 05:26:29 UTC
README
Info
Installation
The preferred way to install this extension is through composer.
add to composer.json
"repositories": [
{
"type": "git",
"url": "https://github.com/skeeks-semenov/yii2-dadata-suggest-api.git"
}
],
Either run
php composer.phar require --prefer-dist skeeks/yii2-dadata-suggest-api "*"
or add
"skeeks/yii2-dadata-suggest-api": "*"
How to use
//App config [ 'components' => [ //.... 'dadataSuggestApi' => [ 'class' => 'skeeks\yii2\dadataSuggestApi\DadataSuggestApi', 'authorization_token' => 'token', 'timeout' => 12, ], //.... ] ]
Examples
Адресные подсказки
$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 }
Определение положения пользователя по ip
$response = \Yii::$app->dadataSuggestApi->detectAddressByIp(\Yii::$app->request->userIP);
Подсказки email
$response = \Yii::$app->dadataSuggestApi->getEmail([ 'query' => 'info@', 'count' => 10 ]);
Подсказки фио
$response = \Yii::$app->dadataSuggestApi->getFio([ 'query' => 'Семен', 'count' => 10 ]);
SkeekS CMS (Yii2) — fast, simple, effective!
skeeks.com | cms.skeeks.com | marketplace.cms.skeeks.com