yii\httpclient\Client::get PHP Method

get() public method

Creates 'GET' request.
public get ( string $url, array | string $data = null, array $headers = [], array $options = [] ) : Request
$url string target URL.
$data array | string if array - request data, otherwise - request content.
$headers array request headers.
$options array request options.
return Request request instance.
    public function get($url, $data = null, $headers = [], $options = [])
    {
        return $this->createRequestShortcut('get', $url, $data, $headers, $options);
    }

Usage Example

Example #1
0
 public function updateWeather()
 {
     $client = new Client();
     $response = $client->get('http://api.wunderground.com/api/fa62a2e2278b3297/conditions/q/PL/Lublin.json')->send();
     if ($response->isOk) {
         $currentObs = $response->data['current_observation'];
         if (isset($currentObs['temp_c'])) {
             $this->temperature = $currentObs['temp_c'];
         }
         if (isset($currentObs['pressure_mb'])) {
             $this->pressure = $currentObs['pressure_mb'];
         }
         if (isset($currentObs['wind_kph'])) {
             $this->wind_speed = $currentObs['wind_kph'];
         }
         if (isset($currentObs['icon'])) {
             $this->conditions = $currentObs['icon'];
         }
         if (isset($currentObs['pressure_trend'])) {
             $this->pressure_trend = $currentObs['pressure_trend'];
         }
         if (isset($currentObs['observation_epoch'])) {
             $this->update_time = $currentObs['observation_epoch'];
         }
         if (isset($currentObs['feelslike_c'])) {
             $this->feels_like = $currentObs['feelslike_c'];
         }
         $this->save();
         return true;
     } else {
         return false;
     }
 }
All Usage Examples Of yii\httpclient\Client::get