CURL for Yii
...requirements of using this extension (e.g. Yii 1.1 or above)... ..You must have CURL enabled in order to use this extension...
BASIC IMPLEMENTATION
'CURL' =>array( 'class' => 'application.extensions.curl.Curl', //you can setup timeout,http_login,proxy,proxylogin,cookie, and setOPTIONS )
ADVANCED IMPLEMENTATION
'CURL' =>array( 'class' => 'application.extensions.curl.Curl', //you can setup timeout,http_login,proxy,proxylogin,cookie, and setOPTIONS //eg. 'options'=>array( 'timeout'=>0, 'cookie'=>array( 'set'=>'cookie' ), 'login'=>array( 'username'=>'myuser', 'password'=>'mypass' ), 'proxy'=>array( 'url'=>'someproxy.com', 'port'=>80, ), //note if you set proxlogin proxy is required 'proxylogin'=>array( 'username'=>'someuser', 'password'=>'somepasswords' ), /* HIRE you have to pay attention, you have to use CURL_CONSTANTS eg. */ 'setOptions'=>array( CURLOPT_UPLOAD => true, CURLOPT_USERAGENT => Yii::app()->params['agent']; ), ), ),
GET EXAMPLES
GOOGLE WEATHER
$data = Yii::app()->CURL->run('http://www.google.com/ig/api?weather='.$place.'&hl=en'); $xml = new SimplexmlElement($data); foreach($xml->weather as $item) { foreach($item->current_conditions as $new) { //For temperature in fahrenheit replace temp_c by temp_f $current_temperature=$new->temp_c['data']; $current_humidity=$new->humidity['data']; } $current_condition=$item->forecast_conditions[0]->condition['data']; $next_temperature=$item->forecast_conditions[1]->high['data']; //to convert Fahrenheit into Celcius $next_temperature=round(($next_temperature-32)*(5/9)); $next_condition=$item->forecast_conditions[1]->condition['data']; } echo " Current temperature :".$current_temperature."<br />"; echo "Current condition : ".$current_condition."<br />"; echo $current_humidity; echo "Tomorrows temperature :".$next_temperature."<br />"; echo "Tomorrows condition : ".$next_condition."<br />";
GOOGLE CALCULATOR
$data = Yii::app()->CURL->run('http://www.google.com/ig/calculator?q='.$amount.$from.'=?'.$to); print_r($data);
GOOGLE GEOCODING
$place = $_GET['place']; $data = Yii::app()->CURL->run('http://maps.google.com/maps/geo?q='.$place.'&output=json&key=ABQIAAAAR3YzPp1SL-w7k-Nhadw6oRRSU9EEwCG8ydw3m56rm2GtI8BohRSHN1qNuRyOrnYS_BNY1_2RnyuYTA'); print_r($data);
POST EXAMPLES
$data = Yii::app()->CURL->run('http://www.atropa.com.hr/index.php?',FALSE, array( 'option'=>'com_content','view'=>'article','id'=>58,'Itemid'=>2 ) ); print_r($data);
Total 9 comments
There is missing a 'N' on line 179 at "CURLOPT_FOLLOWLOCATIO".
Good extension though!
I receive an error
There is the fix of same issue for osCommerce, it can be useful for you.
It would probably be wiser to use a string or constant for the request type. I cannot help it but I hate booleans parameters and if you've worked with payment gateway integration you know why. :) Good job with the extension, nevertheless.
If you set to false your request become POST request.
What is the purposue of the boolean GET parameter, in the run function header?
Thank you...great job!
useful! thx!
I was just about to write one for this :) Thakns!
Nice extension, useful too...
Leave a comment
Please login to leave your comment.