PHP
PHP Tutorial PDF: Basic Book for Beginners (Download NOW)
$20.20 $9.99 for today 4.4 (119 ratings) Key Highlights of PHP Tutorial PDF 269+ pages eBook...
In this tutorial, we are going to look at how you can install and configure CodeIgniter. They are two ways of installation CodeIgniter. You can download the latest version from the CodeIgniter website, or you can use a tool like a composer to automate the installation
In this tutorial, you will learn:
The source code for the CodeIgniter framework is available on the official CodeIgniter website. If you want to download the latest version of the framework, then you should do it from the official web page.
Step 1) Open the following URL in your browser https://codeigniter.com/
The image below shows the download link to the latest version of the framework
Step 2) Clicking the above link will download the framework as a zipped folder. Unzip the contents of CodeIgniter-3.1.10.zip
Step 3) Let's say you want to create a project called the online store. You can follow the following steps to start your project. Create a new directory in on your development drive, e.g, D:\Sites\online-store
Step 4) Open the contents of CodeIgniter-3.1.10, you should be able to see the following files
Copy the above contents to your project directory, e.g., D:\Sites\online-store
Step 5) Just to make sure everything is ok, open the terminal and start the built-in PHP server
cd D:\Sites\ online-store
Run the following command
php -S localhost:3000
load the following URL into your browser
If you see above image, all is working well,
The composer is a package management system for PHP. A package is simply a collection of PHP scripts that work together towards a single goal. Based on this definition, CodeIgniter can even though it's a framework, qualifies to be labeled a package in composer terminologies.
The following image shows how the composer works
The author of CodeIgniter hosts the package at Packagist which is a central repository for PHP packages, etc.
When the developer runs the composer command to download CodeIgniter, Composer communicates with Packagist and downloads the latest release of the package. In addition to installing frameworks such as CodeIgniter, Composer can also be used to;
Step 1) Load the following URL in your browser https://getcomposer.org/download/
Download the setup and follow the installation instructions.
Step 2) Open the command prompt/terminal
Run the following command
composer
You will see the following results
If you can see the above results, then congratulations, you have successfully installed the composer.
Let's now create a new project called online-store
Run the following command
composer create-project CodeIgniter/framework online-store
HERE,
You should be able to see results that is similar to the following
If you are a big fan of commands on the terminal then this is the way to go otherwise you can use the good old fashioned download the zipped file, unzip and happy coding.
Now that we have successfully installed CodeIgniter let's look at the configuration directory
The configuration directory is located in
application/config
HERE,
let's now make some of the most common settings in CodeIgniter
Open application/config/config.php
Base URL
$config['base_url'] = '';
Sets the base URL. If its blank then CodeIgniter will set it for you automatically. If you want to be explicit about your base URL, then you can use the something like the following
$config['base_url'] = 'http://localhost:3000';
HERE,
Class Prefix
CodeIgniter uses the prefix CI_Classname. As a best practice and to avoid collisions with internal classes, you can prefix your class, i.e., MY_Classname. The following line is used to set your class prefix
$config['subclass_prefix'] = 'MY_';
Query Strings
These are parameters that are visited in the URL, i.e., example.com/index.php?q=eggs. If you would like to use such URLs, then you will have to set
$config['enable_query_strings'] = FALSE; To $config['enable_query_strings'] = TRUE;
Other settings
They are many settings that you can set in config.php including date formats, cache and view paths, etc. much of what you configure depends on your application needs
CodeIgniter is an MVC framework. This means it has a single entry point into the application which is index.php. It doesn't matter what URL you access. The all go through index.php. by default, index.php is shown in the URL as shown in the example below
example.com/index.php?q=eggs
The URL looks longer and weird. The good thing is you can configure CodeIgniter to remove that.
Open application/config/config.php
Locate the following line
$config['index_page'] = 'index.php'; Set it to the following $config['index_page'] = '';
HERE,
Next, we need to create the .htaccess that rewrites the URLs
Add a new file .htacces in the root directory of the application
Add the following code
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
HERE,
$20.20 $9.99 for today 4.4 (119 ratings) Key Highlights of PHP Tutorial PDF 269+ pages eBook...
PHP is a server-side scripting language used to develop static and dynamic websites or web...
What is Laravel? Laravel is an open-source web MVC framework for PHP. Laravel is a robust...
What is PHP MVC framework? PHP MVC is an application design pattern that separates the application data...
A Loop is an Iterative Control Structure that involves executing the same number of code a number...
What is Cookie? A cookie is a small file with the maximum size of 4KB that the web server stores...