unknownbits
unknownbits

Reputation: 2885

how to call rest api from view in YII?

I want to call rest API from view in YII.I know how to call it from simple PHP.

From here

But I dont know how to call it in YII manner.what is the right way to call it in YII?

Upvotes: 1

Views: 6048

Answers (2)

Ivan Buttinoni
Ivan Buttinoni

Reputation: 4145

As Yii 1.1

you've not a framework class to do the requests, but you can use Guzzle a powerfull PHP HTTP client:

As Yii 2.0 you can use yii2-httpclient:

Upvotes: 4

eXtreme
eXtreme

Reputation: 876

There isn't Yii way to get the data from API so you can use:

$output = file_get_contents('http://www.hpgloe.com/json/getrec/?lat=37.234&lon=-122.234');

After that you can use CJSON helper to decode the data. For example:

$response = CJSON::decode($output);

Upvotes: -1

Related Questions