Using Composer with CodeIgniter
All web app developers, who have started using modern frameworks like Symfony, Slim, Laravel etc and have wished for the composer support inside their CodeIgniter application, I will try to show you the most efficient and standardized way to achieve this goal. If you are concerned to get support for composer with codeigniter in an existing application, you can totally do that without much worry as well.
Starting from 2015, I never created new PHP project using CodeIgniter. The choice is three:
- Plain PHP - For really simple application.
- Slim Framework - Simple application with expansion possibility.
- Laravel Framework - Application with many dependencies and API integrations.
So, why am I sharing about this? I've developed PHP applications since 2005, so there are possibilities I have returning clients. As most of my past PHP applications were CodeIgniter based and most of my returning clients asked for extra feature, I really need composer support in CodeIgniter.
If you haven’t yet, install composer on your system first. You can get detailed instruction on official composer getting started documentation.
application folder, run:
composer require <package-you-wish-to-add>
and wait for installation finished. Then you should notice composer creating a
vendor folder in your application and code will be installed there. Composer will also create
composer.lock in your
Create a file called
* Description of My_composer
* @author Adjie
application/config folder and add our newly created library
My_composer in the autoloaded libraries list. Sample code:
$autoload['libraries'] = array('My_composer','database','session');
It is as simple as that, and here we are done as well. Great!
If you are not familiar with Composer or PSR-0 support then you should really look into it. The PHP Standards group or PHP-FIG are doing a brilliant job of taming the mess that is third-party PHP code and are building some great standards, which are open to discussion and voted on by some of the best PHP developers around.
Get involved and help PSR-1 and PSR-2 become something brilliant. In the mean-time enjoy all the PSR-0 code and use it wherever the hell you develop.