PHP Requests Library within Codeigniter

前端 未结 5 2440
孤独总比滥情好
孤独总比滥情好 2021-02-20 06:52

I\'m using the requests library (http://requests.ryanmccue.info/) for PHP.

I installed composer and added the following Json configuration in composer.json

5条回答
  •  伪装坚强ぢ
    2021-02-20 07:20

    There is a simple way to use Requests for PHP with Codeigniter.

    You may follow these few easy steps.

    Step - 1

    Unzip latest Requests for PHP zip and copy the contents of the library directory to {codeigniter_directory}/application/third_party/Request-{version} for example you have Requests for PHP 1.6.0 and your CI project is in /usr/sites/www/myciproject then copy the files to /usr/sites/www/myciproject/application/third_party/Requests-1.6.0.

    Step - 2

    Create a file PHPRequests.php in {codeigniter_directory}/application/libraries with this content

    Step - 3

    In your controller you can use Requests by loading PHPRequests library we created in previous step.

    $this->load->library('PHPRequests');
    

    Like this test function

    public function test()
    {
        $this->load->library('PHPRequests');
        $response = Requests::get('https://github.com/timeline.json');
        var_dump($response->body);
    }
    

    Hope this will help.

提交回复
热议问题