CodeIgniter 4 – Sample blog admin panel with bootstrap

Assumption
  • You already had installed Composer
  • You already had installed Visual Studio Code
  • Please note that this is a brief tutorial about creating a blog app in CodeIgniter4. 
Contents
Installation

Type the following command 

composer create-project codeigniter4/appstarter blog

This will create a CodeIgniter4 project named blog. Please note that another type of installation is Manual Installation where you download a zip file that contains the CodeIgniter project.

One of the difference between the Composer and Manual installation is; Manual installation contains a System folder where it contains all the necessary system files. Whereas the Composer installation has the Vendor folder which contains all the system files and the third party libraries.

In this tutorial, we will be using the Composer installation which is the one recommended by CodeIgniter documentation as it can easily update CodeIgniter in the future.

After the installation, open your Visual Studio Code and open the project folder. These are the files and folder that will be created.

Run Local Development Server

We will be using the PHP CLI tool which is the Spark. Spark can only be run inside the CodeIgniter setup – It will not run outside the generated folder when we first create our CodeIgniter4 project.

To run our server, type the following command:

php spark serve

This will allow us to run our app in the web browser using the localhost:8080

Environment Variable

CodeIgniter makes it simple and painless to set Environment Variables by using a “dotenv” file. The term comes from the file name, which starts with a dot before the text “env”. CodeIgniter expects . env to be at the root of your project alongside the app directories.

Go back to your Visual Studio Code and rename the “env” file (from your root folder) to “.env” (with dot in the beginning of the name)

env => .env

Now, let’s open the “.env” file and look for the CI_ENVIRONMENT.

Let’s change the value from “production” (default) to “development” then remove the “#” in the beginning of this line.

Before:

# CI_ENVIRONMENT = production 

After:

CI_ENVIRONMENT = development
Create Site Controller