Author Box

About Us

We are Microsoft Gold partner with its presence across the United States and India. We are a dynamic and professional IT services provider that serves enterprises and startups, helping them meet the challenges of the global economy. We offer services in the area of CRM Consultation and implementation, Application development, Mobile application development, Web development & Offshore Development.

What is CodeIgniter? How to setup CodeIgniter on your system?

By Pooja Sharma / January 24, 2020

April 28, 2020
What is CodeIgniter? How to setup CodeIgniter on your system?

What is CodeIgniter?

CodeIgniter is an open-source MVC framework for application development in php. It is simple to setup and easy to configure which makes it widely used by developers. It provides various libraries and helpers which makes it faster and easy to add functionality. 

System Requirements: 

  • Php version 5.6 or newer. 
  • MySQL 5.1 or newer. 

How to download and setup Codelgniter?

      1. Download version 3.1.11 Download

     2. Unzip the folder inside server. 

     3. Configure base URL : go to application/config/config.php file.  

        1.Set $config[‘base_url’] = ‘site_url’; 

         2.set index page : $config['index_page'] = ''; 

     4. Database configuration : go to application/config/database.php file. 

Set 

$db['default'] = array( 

    'dsn'   => '', 

    'hostname' => 'localhost', 

    'username' => 'user_name', 

    'password' => 'password', 

    'database' => 'database_name', 

    'dbdriver' => 'mysqli', 

    'dbprefix' => '', 

    'pconnect' => FALSE, 

    'db_debug' => (ENVIRONMENT !== 'production'), 

    'cache_on' => FALSE, 

    'cachedir' => '', 

    'char_set' => 'utf8', 

    'dbcollat' => 'utf8_general_ci', 

    'swap_pre' => '', 

    'encrypt' => FALSE, 

    'compress' => FALSE, 

    'stricton' => FALSE, 

    'failover' => array(), 

    'save_queries' => TRUE 

); 

By changing the $db array variable to ‘test’ it can be set for test environment. 

  1. Auto Load configuration: $autoload[‘libraries’]= array[‘libraries to be included for autoload’]; 

Application flow in CodeIgniter:

  1. The index.php provide frontend controller for initializing base resource. 

      2. Router controls the http request, if file is already in cache it is sent directly to the browser. 

      3. Before passing to the controller data is checked by security. 

      4. It’s the controller which load the models to provide access to database, libraries and helpers etc. 

Routing in CodeIgniter:

Routes are used for listening URL request. If a request matches a predefined route it is redirected to the URL address otherwise page not found exception is thrown. 

Routes are defined in typical manner in CodeIgniter: 

Site-URL / controller-name / method-in-controller / any-parameter. 

Session in CodeIgniter  

Session data is available throughout the site but to use these data we must initialize the session library. 

$this->load->library('session'); 

After the library is loaded, session instance can be used : 

$this->session 

Session value are stored as : 

$this->session->set_userdata('variable-name', 'variable_value'); 

Passing data from controller to view in CodeIgniter  

View is loaded from controller by : 

$this->load->view(‘view-name’) 

We can pass data to view as an array in form of second parameter in view() function. 

$data[‘data-to-pass’] = ‘name’; 

$this->load->view(‘view-name’,$data) 

The only twist is when data is retrieved in ‘view’.Parameter passed in array becomes the variable in view. 

echo ‘name = ’.$data-to-pass; 

Passing data from view to controller in CodeIgniter

Data is passed from view to controller in form post data. 

<form method =”post” action=”<? Base_url(); ?>controller_name/controller_method_name”> 

While on receiving end: 

$form_data = $this->input->post();  

Passing data from controller to Model in CodeIgniter 

Before we use the service of a model, we must load the module into our controller class. 

$this->load->model(‘model-name’); 

If we load model in constructor of our controller class, we don’t need to load it again anywhere else in the controller class. So, we can call the model function inside controller function and pass the data as parameter to model function. 

$this->model-name->model-function-name($data-to-pass); 

Hope this article is helpful for you to setup your first CodeIgniter project locally. If you have any query please feel free to contact us. 

[sc name="Web Development"] [apss_share]

What is CodeIgniter?

CodeIgniter is an open-source MVC framework for application development in php. It is simple to setup and easy to configure which makes it widely used by developers. It provides various libraries and helpers which makes it faster and easy to add functionality. 

System Requirements: 

  • Php version 5.6 or newer. 
  • MySQL 5.1 or newer. 

How to download and setup Codelgniter?

      1. Download version 3.1.11 Download

     2. Unzip the folder inside server. 

     3. Configure base URL : go to application/config/config.php file.  

        1.Set $config[‘base_url’] = ‘site_url’; 

         2.set index page : $config[‘index_page’] = ”; 

     4. Database configuration : go to application/config/database.php file. 

Set 

$db[‘default’] = array( 

    ’dsn’   => ”, 

    ’hostname’ => ‘localhost’, 

    ’username’ => ‘user_name’, 

    ’password’ => ‘password’, 

    ’database’ => ‘database_name’, 

    ’dbdriver’ => ‘mysqli’, 

    ’dbprefix’ => ”, 

    ’pconnect’ => FALSE, 

    ’db_debug’ => (ENVIRONMENT !== ‘production’), 

    ’cache_on’ => FALSE, 

    ’cachedir’ => ”, 

    ’char_set’ => ‘utf8’, 

    ’dbcollat’ => ‘utf8_general_ci’, 

    ’swap_pre’ => ”, 

    ’encrypt’ => FALSE, 

    ’compress’ => FALSE, 

    ’stricton’ => FALSE, 

    ’failover’ => array(), 

    ’save_queries’ => TRUE 

); 

By changing the $db array variable to ‘test’ it can be set for test environment. 

  1. Auto Load configuration: $autoload[‘libraries’]= array[‘libraries to be included for autoload’]; 

Application flow in CodeIgniter:

  1. The index.php provide frontend controller for initializing base resource. 

      2. Router controls the http request, if file is already in cache it is sent directly to the browser. 

      3. Before passing to the controller data is checked by security. 

      4. It’s the controller which load the models to provide access to database, libraries and helpers etc. 

Routing in CodeIgniter:

Routes are used for listening URL request. If a request matches a predefined route it is redirected to the URL address otherwise page not found exception is thrown. 

Routes are defined in typical manner in CodeIgniter: 

Site-URL / controller-name / method-in-controller / any-parameter. 

Session in CodeIgniter  

Session data is available throughout the site but to use these data we must initialize the session library. 

$this->load->library(‘session’); 

After the library is loaded, session instance can be used : 

$this->session 

Session value are stored as : 

$this->session->set_userdata(‘variable-name‘, ‘variable_value’); 

Passing data from controller to view in CodeIgniter  

View is loaded from controller by : 

$this->load->view(‘view-name’) 

We can pass data to view as an array in form of second parameter in view() function. 

$data[‘data-to-pass’] = ‘name’; 

$this->load->view(‘view-name’,$data) 

The only twist is when data is retrieved in ‘view’.Parameter passed in array becomes the variable in view. 

echo ‘name = ’.$data-to-pass; 

Passing data from view to controller in CodeIgniter

Data is passed from view to controller in form post data. 

<form method =”post” action=”<? Base_url(); ?>controller_name/controller_method_name”> 

While on receiving end: 

$form_data = $this->input->post();  

Passing data from controller to Model in CodeIgniter 

Before we use the service of a model, we must load the module into our controller class. 

$this->load->model(‘model-name’); 

If we load model in constructor of our controller class, we don’t need to load it again anywhere else in the controller class. So, we can call the model function inside controller function and pass the data as parameter to model function. 

$this->model-name->model-function-name($data-to-pass); 

Hope this article is helpful for you to setup your first CodeIgniter project locally. If you have any query please feel free to contact us. 

Web Development Services

Are you looking for a reliable web development company? Our highly skilled web developers enables us to deliver result oriented web development services. Contact our team to understand, how we can help you in achieving your business goals.

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x