How to Write PHP Code with CodeIgniter Framework

10:19


Well, PHP (HYPERTEXT PREPROCESSOR) is a programming language for web development and we can write PHP code in different ways but, if I talk about MVC design pattern (Model View Controller) it is the best design pattern for making projects either using PHP or any other programming language.

On the basis of this MVC pattern a framework is in market and that framework is widely used for making PHP projects with MVC pattern.
The framework is named as CODEIGNITER. Today I’m writing this tutorial on how we can write or start writing PHP code with CodeIgniter.


What is CodeIgniter?

If I say in very simple words it is an open source web application framework widely and rapidly using in world for making dynamic websites with PHP.

CodeIgniter is based on very popular MVC (Model View Controller) development design pattern. CodeIgniter is very famous among all PHP frameworks because it is very faster and lighter.


Steps for Starting Codeigniter Project



  • And, after that place the extracted folder of that downloaded file in the localhost folder (In my case I’m using xampp server for executing project so, I placed that extracted codeigniter folder in C:\xampp\htdocs). 
Note: you can change the name of folder with your project name

  • Now start the server you have in your system (I’m using xampp server) after starting server hit the url in your browser


http://localhost/[NAME_OF_THE_FOLDER_PLACED_IN_LOCALHOST]/

         You will see a welcome page of CodeIgniter in your browser
  • Now you have to alter some files before starting your own project, first open 

C:\xampp\htdocs\codeigniter.finallygot.com\application\config\config.php


          file and change value of $config['base_url'] with your base url of project                                   (http://localhost/codeigniter.finallygot.com/)
  • If you want to use database in your project then you have to change file


C:\xampp\htdocs\codeigniter.finallygot.com\application\config\database.php

        In front of hostname you have to write your database hostname
        In front of username you have to write username of database
        In front of password you have to write password of database
        In front of database you have to write database name.
  • After this open file

C:\xampp\htdocs\codeigniter.finallygot.com\application\config\routes.php

       and change the value of  $route['default_controller'] from welcome to home or what          you want to make load by controller.

  • Open 
C:\xampp\htdocs\codeigniter.finallygot.com\application\controllers

         directory and create a PHP name as home.php (as written in route value)

  • In home.php first write a line of code to prevent script from direct access.

<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);


        After that write a class named same as file name (home) this class should extends               CI_Controller.



  • Open C:\xampp\htdocs\codeigniter.finallygot.com\applcation\views
          and make a file for home controller name could be any think let we take h_view.php.

  •       Open this h_view.php file and write some html code that we could see on browser.


  • Open the home controller we have made (home.php) and make a index() function in the Home class and write a line of code in index() function for viewing our view file on browser.




  • Now last step is to open home page in browser


http://localhost/[NAME_OF_THE_FOLDER_PLACED_IN_LOCALHOST]/

        you will see what you have written in h_view.php your view page but this page is                   called by home.php controller (this controller is base or default controller set in                       routes.php).


If any one of reader have suggestions or queries can comment in comment box…

You Might Also Like

0 comments

If you have any questions or suggestions, you are free to ask, i will appreciate that and, i will try my best...

Check Out