Skip to content

How to use Composer

groucho75 edited this page Nov 25, 2014 · 9 revisions

This starter kit comes ready to use Composer.

Setup packages

You can add the packages editing the require section in the included composer.json file, e.g.:

{
    "config": {
        "vendor-dir": "application/third_party/composer"
    },
    "require": {
        "erusev/parsedown": "dev-master"
    }
}

All the downloaded packages will be installed in application/third_party/composer.

1) Quick use

Now you can use the library in your controller, e.g.

$parsedown = new Parsedown();
echo $parsedown->parse( file_get_contents( FCPATH.'/README.md' ) );

2) Advanced use

Maybe you like to use the CI load method also for Composer packages.

E.g. for the above Markdonw library, you should create application/libraries/parsedown_lib.php file with at least the following code:

 <?php defined('BASEPATH') OR exit('No direct script access allowed.');
/**
 * Make a CodeIgniter library from the composer-autoloaded class 
 */
class Parsedown_lib extends Parsedown {	
}  

Now in your controller you can load and use in CI standard way, e.g.:

$this->load->library('Parsedown_lib');		
echo $this->parsedown_lib->parse( file_get_contents( FCPATH.'/README.md' ) );	

For more info about creating new libraries you can start from CI doc.

Clone this wiki locally