This article will be dealing with the Codeingiter framework. Before we start, if you don’t have a properly set workspace, I suggest you take a look at This Article.

I have chosen Codeigniter 3 for it’s ease of use and to let you get started easily creating basic applications. Later articles will cover more complex Frameworks such as Symfony 4, and probably more complex architectures such as SOA.

Using composer, we will install codeigniter to a new directory using this console command :

composer create-project kenjis/codeigniter-composer-installer my-folder

This command should output something like this :

Installing kenjis/codeigniter-composer-installer (v0.4.8)
  - Installing kenjis/codeigniter-composer-installer (v0.4.8): Downloading (100%)         
Created project in ci-crm
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing codeigniter/framework (3.1.7): Downloading (100%)         
kenjis/codeigniter-composer-installer suggests installing kenjis/codeigniter-cli (A command-line tool for CodeIgniter 3.0)
kenjis/codeigniter-composer-installer suggests installing kenjis/ci-phpunit-test (An easier way to use PHPUnit with CodeIgniter 3.0)
kenjis/codeigniter-composer-installer suggests installing kenjis/codeigniter-ss-twig (A Simple and Secure Twig integration for CodeIgniter 3.0)
kenjis/codeigniter-composer-installer suggests installing kenjis/codeigniter-doctrine (A simple Doctrine integration for CodeIgniter 3.0)
kenjis/codeigniter-composer-installer suggests installing kenjis/codeigniter-deployer (A Deployment Tool for CodeIgniter 3.0)
codeigniter/framework suggests installing paragonie/random_compat (Provides better randomness in PHP 5.x)
Writing lock file
Generating autoload files
> Kenjis\CodeIgniter\Installer::postInstall
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing mikey179/vfsstream (v1.1.0): Loading from cache
Writing lock file
Generating autoload files
==================================================
`public/.htaccess` was installed. If you don't need it, please remove it.
If you want to install translations for system messages or some third party libraries,
$ cd <codeigniter_project_folder>
$ php bin/install.php
The above command will show help message.
See <https://github.com/kenjis/codeigniter-composer-installer> for details
==================================================

Let’s add one more component, the debug toolbar :

php bin/install.php codeigniter-develbar master

Using your favorite text editor or code IDE, open the folder to display it’s content and start working on the file.

First thing I like to add, is the ability to run the PHP Built-in web server, added as of PHP 5.4, for that I use a simple composer trick :

{
    # add this after "require-dev"
    ,"scripts": {
        "run": [
            "echo 'Started web server on http://localhost:8888'",
            "php -S localhost:8888 -t public"
        ]
    }
}

And of course, if you want to work with version control (in this case git)

git init

Make sure that, If you install Codeigniter using “kenjis” package, to disable autoloading the database and the session libraries, to avoid unnecessary errors at this level, we will get to it later

# File application/config/autoload.php
# edit this line (Line 63)

$autoload['libraries'] = array('database', 'session');

# as such 

$autoload['libraries'] = array();

Then simply run this command to start the built-in web server

composer run

if you head to your browser now, using this URL : http://localhost:8888 you should see something like this

Congratulations ! That would conclude our first tutorial with Codeigniter 3.

Leave a comment