Simply putting, CodeIgniter is a light-weight tool-kit to develop PHP-based applications. This framework provides you with a rich set of libraries to carry out common tasks as well as a simple structure to easily access them. Moreover, you can make your own libraries and accelerate your website’s development process.
Like many other PHP frameworks, CodeIgniter too supports MVC architecture. And it doesn’t require a template engine. But the most amazing thing about CodeIgniter is that It does not compel you to use a command-line interface. You don’t need to adhere to restrictive coding rules to develop a CodeIgniter app. It provides exceptional performance with simple coding. Putting in one sentence, CodeIgniter is a perfect framework for today’s developers.
Features of CodeIgniter
- MVC Architecture
- Light-Weight
- Fully Featured Database Classes
- Form and Data Validation
- FTP classes
- Localization
- Pagination
- Session Management
- Full Page caching
- Error Logging
- Zip Encoding Classes
- XML-RPC Library
- Calendaring Class
- Benchmarking
- Unit Testing Class
How to Install CodeIgniter Framework
Step 1:
Download the CodeIgniter framework from here.
You will get a zip file downloaded.
Step 2:
Extract a zip file in your xampp/htdocs/ directory and rename the folder.
Now run https://localhost/[folder_name]/ in your browser to check if it is working or not.
Step 3: Setup Environment File
Navigate to the application/config folder and create a new environment.php file
<?php
defined(‘BASEPATH’) OR exit(‘No direct script access allowed’);
$config[‘custom_config‘] = true;
define( ‘DB_HOSTNAME’, ‘localhost‘ );
define( ‘DB_USERNAME’, ‘root‘ );
define( ‘DB_PASSWORD’, ‘‘ );
define( ‘DB_DATABASE’, ‘DB_NAME );
$config[‘base_url‘] = ‘http://localhost/project_name/‘;
Note: Setup your all configurations in the environment.php file only
After that, open file and add following code:
$autoload[‘config’] = array( );
if ( file_exists ( __DIR__ . ‘/environment.php‘ ) ) {
$autoload[‘config‘][] = ‘environment’;
}
Step 4:
Setup database connection in application/config/database.php
‘hostname’ => defined(‘HOSTNAME’)? HOSTNAME: ‘localhost’, ‘username’ => defined(‘DB_USERNAME’)? DB_USERNAME: ‘root’, ‘password’ => defined(‘DB_PASSWORD’)? DB_PASSWORD: ”, ‘database’ => defined(‘DB_DATABASE’)? DB_DATABASE: ‘db_name‘,
Step 5:
Create a new resources folder in the root directory.
Within this resources folder, create two new folders and js.
These folders will store CSS and JavaScript files respectively.
Step 6: Basic Configuration
Open autoload.php and load database and session library.
$autoload[‘libraries’] = array(‘database’, ‘session‘);
And load url, cache, cookie, and security helper classes.
$autoload[‘helper’] = array(‘url‘, ‘cache’, ‘cookie‘, ‘security’);
Step 7: Load js File to load Particular View File
Open controller->function and add page key inside header object.
public function app() {
$header = array(
‘page’ => ‘page_name‘, // add page name
);
$this->load->view(‘front-end/include/header’, $header);
$this->load->view(‘front-end/app’);
$this->load->view(‘front-end/include/footer’);
}
After that, open the footer file and add page key conditions
<?php if(!empty($page) && $page == ‘page_name‘ ){ ?>
<script src=“<?php echo assets()?>/js/this-page.js” ></script>
<?php}?>
Now load css file in the same way.
Step 8: Remove index.php from url
1. Create a .htaccess file at the root of the project.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
2. Remove index.php at the root/application/config/config.php
$config[‘index_page‘] = ”;
Work Rules
You will have to adhere to some rules when you use CodeIgniter Framework
- Make a habit of keeping the sidebar, header, footer, and main content page in separate files.
- Write JavaScript code in a separate js file rather than writing it in a view file
- Submit your app only after carrying out proper testing.
- Create any custom js file into the resources/js directory.
- Use base URL instead of static URL
- Show proper exception messages to users on errors and validation fails.
- Setup JavaScript validation and server-side validation in every form.
Useful VS Code Extensions
There are many useful CodeIgniter extensions available in Visual Studio Code editor to supercharge your web development. These extensions provide extra features which help developers to easily carry out complex tasks. Here will talk about two such very useful extensions.
CI Snippet 2
The CodeIgniter Snippet 2 extension provides you with various text snippets. These snippets will help you speed up your project development. They will prompt the intended code when they are typed.
CI REST API Snippet
CI REST API Snippet offers snippets that are helpful in REST API-related tasks.
Conclusion
I hope now you are thoroughly aware of the installation process of the CodeIgniter framework. If you have any questions regarding this post, let me know in the comment section below. Share this article with your friends.