-
Notifications
You must be signed in to change notification settings - Fork 0
/
CurlYii.php
56 lines (46 loc) · 1.29 KB
/
CurlYii.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Component Curl
* Simple Yii component to Curl. This Component permited you comunique with other Yii Framework.
* For usage CurlYii component is very simple. Example:
*
* $curl = new CurlYii( 'url_of_server');
* $curl->action = 'module/Controller/action';
* $curl->method = 'POST'; // GET is default
* $curl->data = array('key' => 'value');
* $curl->run();
*
* @author Caio Vncius <[email protected]>
*/
class CurlYii extends CComponent
{
public $url;
public $action;
public $redirect = false;
public $output = true;
public $method = 'GET';
public $data;
public function __construct( $url )
{
$this->url = $url;
}
public function run()
{
if(! empty( $this->action ))
$cUrl = $this->url . '/index.php?r=' . $this->action;
$curl = curl_init();
// define a url
curl_setopt($curl, CURLOPT_URL, $cUrl);
if( $this->output == true)
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
else
curl_setopt($curl, CURLOPT_RETURNTRANSFER, false);
if( $this->method == 'POST')
curl_setopt($curl, CURLOPT_POST, true);
if(!empty( $this->data ))
curl_setopt($curl, CURLOPT_POSTFIELDS, $this->data);
$response = curl_exec($curl);
curl_close($curl);
print_r( $response );
}
}