Home  >  Article  >  Development Tools  >  Introduction to the steps and methods of dependency packages installed by CI framework using composer

Introduction to the steps and methods of dependency packages installed by CI framework using composer

藏色散人
藏色散人forward
2019-12-12 15:08:012480browse

The following tutorial column of composer uses will introduce to you the steps and methods of dependency packages installed by CI framework using composer. I hope it will be helpful to friends in need!

Introduction to the steps and methods of dependency packages installed by CI framework using composer

This article is for Linux systems, windows. The first step is to install according to the composer official website. The following steps are the same

step 1 Global installationcomposer

$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer

step 2 Create composer.json to your project root directory

{
  "require": {
    "kriswallsmith/buzz": "*"
  }
}

Here will add a Buzz package to handle HTTP Request / Response PHP 5.3.x classes.

step 3 Execute the following command to download the dependency package

$ composer install

After that you will notice that composer created a ./vendors in your application directory and the code is also in it.

step 4 in Add automatic loading of packages in the project

Add the following line in your index.php

require_once './vendor/autoload.php';

needs to be loaded in front of

require_once BASEPATH.'core/CodeIgniter.php';

step 5 Test

Examples are as follows:

class Test extends CI_Controller
{
  public function index()
  {
    $browser = new Buzz\Browser();
    $response = $browser->get('http://www.baidu.com');
    echo $browser->getLastRequest()."\n";
    echo $response;
  }
}

To view more available packages, you can view Packagist (https://packagist.org/explore/)

The above is the detailed content of Introduction to the steps and methods of dependency packages installed by CI framework using composer. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete