Code Igniter Interview
Indoscie Technologies is Web Design and Development, SEO, PPC, Local Listing,
Adwords, E-mail Marketing, Digital Marketing service and solutions providers at a very affordable cost.
CodeIgniter Interview Questions
1) Explain what is Codeigniter?
2) What is the current version of Codeigniter?
3) How to check the version of CodeIgniter framework?
4) List Databases supported By Codeigniter Frameworks?
5) List some features provided by CodeIgniter?
6) Explain helpers in CodeIgniter and how to load helper file?
7) Explain routing in CodeIgniter?
8) What are hooks in CodeIgniter? List them?
9) List Common Functions in Codeigniter?
10) How do you set default timezone in Codeigniter ?
11) How to add / link an images/CSS/JavaScript from a view in CI?
12) What is inhibitor are Codeigniter?
13) How
can you remove index.php from URL in Codeigniter?
14) How will you add or load a model in Codeigniter?
15) What are Sessions In CodeIgniter? How to read, write or remove session in CodeIgniter?
16) How to get last inserted id in CodeIgniter?
17) How you will use or load CodeIgniter libraries
18) What is the CLI? Why we use CLI in Codeigniter?
19) How to do 301 redirects in CodeIgniter?
20) How to check a field or column exists in a table or not in Codeigniter?
21) What is_cli() method does in Codeigniter?
22) Explain Codeigniter’s application Flow Chart?
23) How to set or get config variables in Codeigniter?
24) How to
delete a record in Codeigniter?
25) How to implement validations in Codeigniter?
Last Updated: Dec 09, 2019,
Posted in Interview Questions,
35 Questions
CodeIgniter Interview Questions
What is CodeIgniter?
CodeIgniter is easy to use an open-source MVC based framework for PHP. It is a loosely coupled framework that is used for the rapid development of websites and mobile APIs.Here you can read about CodeIgniter helpers, sessions, hooks, Routing, Constants ORM supported by Codeigniter and more.
Quick Questions About CodeIgniter
CodeIgniter is written In PHP Programming Language
CodeIgniter is a Open Source Loosely Coupled
MVC Framework
CodeIgniter is developed By BCIT Recreation Services
CodeIgniter is based on MVC architectural pattern
CodeIgniter Dependencies Php 5.6+,MYSQL 5.1+,PDO Driver
CodeIgniter Licence MIT License
CodeIgniter Current Stable release 3.1.11
Below are the list of Best CodeIgniter Interview Questions and Answers
1) Explain what is Codeigniter?
CodeIgniter is a powerful MVC based PHP framework with a very small footprint, built for developers who need a simple and elegant toolkit to create full-featured web applications.
VDO.AI
2) What is the current version of Codeigniter?
As on Sept
19, 2019 CodeIgniter 3.1.11 is the latest version of the framework. You can download it from here
3) How to check the version of CodeIgniter framework?
In system/core/CodeIgniter.php, check CI_VERSION constant value define(‘CI_VERSION’, ‘3.0.6’);
4) List Databases supported By Codeigniter Frameworks?
Following Databases supported are supported by Codeigniter Frameworks
MySQL (5.1+) via the MySQL (deprecated), MYSQLI and PDO drivers
Oracle via the oci8 and PDO drivers
PostgreSQL via the Postgre and PDO drivers
MS SQL via the MsSQL, Sqlsrv (version 2005 and above only) and PDO
drivers
SQLite via the SQLite (version 2), sqlite3 (version 3) and PDO drivers
CUBRID via the Cubridand PDO drivers
Interbase/Firebird via the iBase and PDO drivers
ODBC via the ODBC and PDO drivers (you should know that ODBC is actually an abstraction layer)
5) List some features provided by CodeIgniter?
Framework with a small footprint
Simple solutions over complexity
Clear documentation
Exceptional performance
Strong Security
Nearly zero configuration
6) Explain helpers in CodeIgniter and how to load helper file?
As the name suggests, helpers help you with tasks.Each helper file is simply a collection of
functions in a particular category.They are simple, procedural functions.Each helper function performs one specific task, with no dependence on other functions.
CodeIgniter does not load Helper Files by default, so the first step in using a Helper is to load it. Once loaded, it becomes globally available in your controller and views.
Helpers are typically stored in your system/helpers, or application/helpers directory
Loading a helper file is quite simple using the following method:
$this->load->helper('name');
Where name is the file name of the helper, without the .php file extension or the
“helper†part.
Read More
7) Explain routing in CodeIgniter?
In Software engineering routing is the process of taking a URI endpoint (that part of the URI which comes after the base URL) and decomposing it into parameters to determine which module, controller, and action of that controller should receive the request.In Codeigniter typically there is a one-to-one relationship between a URL string and its corresponding controller class/method.The segments in a URI normally follow this pattern:example.com/class/function/id/.In CodeIgniter, all routing rules are defined in your application/config/routes.php file.
8) What are hooks in
CodeIgniter? List them?
CodeIgniter’s Hooks feature provides a way to modify the inner workings or functionality of the framework without hacking the core files.
The following is a list of available hook points.
pre_system Called very early during system execution.
pre_controller Called immediately prior to any of your controllers being called.
post_controller_constructor Called immediately after your controller is instantiated, but prior to any method calls happening.
post_controller Called immediately after your controller is fully executed.
display_override Overrides the _display() method.
cache_override
Enables you to call your own method instead of the _display_cache() method in the Output Library. This permits you to use your own cache display mechanism.
post_system Called after the final rendered page is sent to the browser, at the end of system execution after the finalized data is sent to the browser.
Read More
9) List Common Functions in Codeigniter?
CodeIgniter uses a few functions for its operation that are globally defined, and are available to you at any point. These do not require loading any libraries or helpers.
is_php($version)
is_really_writable($file)
config_item($key)
set_status_header($code[, $text =
â€])
remove_invisible_characters($str[, $url_encoded = TRUE])
html_escape($var)
get_mimes()
is_https()
is_cli()
Read Best 80+AngularJS Interview Questions
10) How do you set default timezone in Codeigniter ?
To set default timezone in Codeigniter open application/config.php file and add below code in it.
date_default_timezone_set('your timezone');
11) How to add / link an images/CSS/JavaScript from a view in CI?
In Codeigniter, you can link images/CSS/JavaScript by using the absolute path to your resources.
Something like below
// References your
$config['base_url']
<img src="<?php echo site_url('images/myimage.jpg'); ?>" />
12) What is inhibitor are Codeigniter?
An inhibitor is an error handling class in Codeigniter. It uses PHP ‘s native functions like register_shutdown_function , set_exception_handler, set_error_handler to handle parse errors, exceptions, and fatal errors.
13) How can you remove index.php from URL in Codeigniter?
Follow below steps to index.php from URL in Codeigniter
Step 1: Open config.php and replaces
$config['index_page'] = "index.php" to $config['index_page'] = ""
and
$config['uri_protocol'] ="AUTO" to $config['uri_protocol'] = "REQUEST_URI"
Step 2: Change your .htaccess file to
RewriteEngine on
RewriteCond $1 !^(index.php|[Javascript / CSS / Image root Folder name(s)]|robots.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
14) How will you add or load a model in Codeigniter?
In Codeigniter, models will typically be loaded and called from within your controller methods. To load a model you will use the following method:
$this->load->model('model_name');
If your model is located in a sub-directory, include the relative path from your model’s directory. For example, if you have
a model located at application/models/blog/Posts.php you’ll load it using:
$this->load->model('blog/Posts');
Once your Model loaded, you will access its methods using an object with the same name as your controller:
Example
class Blog_controller extends CI_Controller {
public function blog()
{
$this->load->model('blog');
$data['query'] = $this->blog->get_last_ten_entries();
$this->load->view('blog', $data);
}
}
15) What are Sessions In CodeIgniter? How to read, write or remove session in CodeIgniter?
Sessions in CodeIgniter
In CodeIgniter Session class allows you maintain a user’s “state†and track their activity while they are browsing your website.
In order to use session, you need to load Session class in your controller.
$this->load->library(‘session’); method is used to sessions in CodeIgniter
$this->load->library('session');
Once loaded, the Sessions library
object will be available using:
$this->session
Reading session data in CodeIgniter
Use $this->session->userdata(); method of session class to read session data in CodeIgniter.
Usage
$this->session->userdata('your_key');
You can also read a session data by using the magic getter of CodeIgniter Session Class
Usage
$this->session->item
Where an item is the name of the key you want to retrieve.
Creating a session in CodeIgniter
Session’s Class set_userdata() method is used to create a session in CodeIgniter. This method takes
an associative array containing your data that you want to add in session.
Example
$newdata = array(
'username' => 'johndoe',
'email' => 'johndoe@some-site.com',
'logged_in' => TRUE
);
$this->session->set_userdata($newdata);
If you want to add userdata one value at a time, set_userdata() also supports this syntax:
$this->session->set_userdata('some_name', 'some_value');
Removing Session Data
Session’s Class unset_userdata() method is used to remove a session
data in CodeIgniter. Below are example usages of same.
Unset particular key
$this->session->unset_userdata('some_key');
Unset an array of item keys
$array_items = array('username', 'email');
$this->session->unset_userdata($array_items);
Read More https://www.codeigniter.com/userguide3/libraries/sessions.html
16) How to get last inserted id in CodeIgniter?
CodeIgniter DB Class insert_id() method is used to get last insert id.
Usage:
function add_post($post_data){
$this->db->insert('posts',
$post_data);
$insert_id = $this->db->insert_id();
return $insert_id;
}
17) How you will use or load CodeIgniter libraries
$this->load->library(‘library_name’); method is used to load a library in CodeIgniter.
Usage:
//Loading Cart library
$this->load->library('cart');
Using Cart library methods
$data = array(
'id' => 'sku_9788C',
'qty' => 1,
'price' => 35.95,
'name'
=> 'T-Shirt',
'options' => array('Size' => 'L', 'Color' => 'Red')
);
$this->cart->insert($data);
18) What is the CLI? Why we use CLI in Codeigniter?
CLI is a text-based command-line interface for interacting with computers via a set of commands.
In Codeigniter, we can use CLI for
Run your cronjobs without needing to use wget or curl
Make your cron-jobs inaccessible from being loaded in the URL by checking the return value of is_cli().
Make interactive “tasks†that can do things like set permissions, prune cache
folders, run backups, etc.
Helps to integrate Codeigniter with other applications in other languages. For example, a random C++ script could call one command and run code in your models!
19) How to do 301 redirects in CodeIgniter?
We can use redirect helper to do 301 redirects in Codeigniter.
Syntax :
redirect($uri = '', $method = 'auto', $code = NULL)
Parameter:
$uri (string) – URI string
$method (string) – Redirect method (‘auto’, ‘location’ or ‘refresh’)
$code (string) – HTTP Response code (usually
302 or 303)
Return type: void
Sample Usage:-
redirect('/posts/13', 'New location', 301);
20) How to check a field or column exists in a table or not in Codeigniter?
Code for Checking a field or column exists or not in a Codeigniter table.
if ($this->db->field_exists('field_name', 'table_name'))
{
// some code...
}
21) What is_cli() method does in Codeigniter?
In Codeigniter is_cli() method is used to check request is from the command line or not.
Returns TRUE if the application is run through the command line and FALSE if
not.
22) Explain Codeigniter’s application Flow Chart?
Below images give you an understanding of how data flows throughout the system in Codeigniter.
Codeigniter Application Flow Chart
The index.php serves as the front controller, initializing the base
resources needed to run CodeIgniter.
The Router examines the HTTP request to determine what should be done
with it.
If a cache file exists, it is sent directly to the browser, bypassing
the normal system execution.
Security. Before the application controller is loaded, the HTTP
request and any user submitted data are filtered for
security.
The Controller loads the model, core libraries, helpers, and any
other resources needed to process the specific request.
The finalized View is rendered then sent to the web browser to be
seen. If caching is enabled, the view is cached first so that on
subsequent requests it can be served.
Source: https://www.codeigniter.com/user_guide/overview/appflow.html
23) How to set or get config variables in Codeigniter?
In Codeigniter by default all config variables are located at “application/config/config.php†file.
Below is the way to set or get a config variable in Codeigniter
// Setting a config
variable dynamically
$this->config->set_item('variable_name', value);
// Getting value of config variable in Codeigniter.
$this->config->item('variable_name');
24) How to delete a record in Codeigniter?
In Codeigniter, delete function is used to delete the one or more row data from a table.
//DELETE FROM table WHERE id = $id
$conditions =['id' => $id]
$this->db->delete('table_name', $conditions);
// Deleting records from more than one tables in one go
$id=1;
$tables = array('table1', 'table2', 'table3');
$this->db->where('id',
$id);
$this->db->delete($tables);
25) How to implement validations in Codeigniter?
26) What is the default URL pattern used in Codeigniter framework?
In CodeIgniter, URLs are designed to be search-engine and human-friendly.CodeIgniter uses a segment-based approach rather than using “query string†based approach.
abc.com/user/edit/ramesh
The default URL pattern in CodeIgniter consists of 4 main components. They are :
A server name (abc.com)
A Controller (user)
An Action or method (edit)
An optional action parameter (ramesh)
Prepare 10 Essential Magento Interview
Questions
27) How to get random records in MySQL using CodeIgniter?
order_by function is used to order the records from a table in CodeIgniter.
// Getting random rows from database in CodeIgniter
$this->db->select('*');
$this->db->from('table_name');
$this->db->order_by("column_name", "random");
$result = $this->db->get()->result();
28) Why CodeIgniter is called as loosely based MVC framework?
Codeigniter Is Called a loosely based MVC framework, this is because unlike others the controllers’ classes such as models and views are not mandatory in CodeIgniter. Moreover, one can modify
CodeIgniter to utilize HMVC as well.
29) What is an ORM, List ORM’s for CodeIgniter?
Object-relational mapping (ORM) is programming technique for converting data between incompatible type systems using object-oriented programming languages. Below is the list of ORM’s supported by CodeIgniter Framework
DataMapper
Doctrine
Gas ORM
30) Explain URL Helper? Can you list some commonly used URL helpers in Codeigniter?
https://codeigniter-id.github.io/user-guide/helpers/url_helper.html
31) List the resources that can be autoloaded in Codeigniter?
The following items can be loaded automatically:
Classes found in
the libraries/ directory
Helper files found in the helpers/ directory
Custom config files found in the config/ directory
Language files found in the system/language/ directory
Models found in the models/ folder
To autoload resources, open the application/config/autoload.php file and add the item you want loading to the autoload array. You’ll find instructions in that file corresponding to each type of item.
32) In which files routes are defined in Codeigniter?
All Routing rules in Codeigniter are defined in your application/config/routes.php file.
33) In which directory logs are saved in Codeigniter? How to
enable error logging in Codeigniter?
By default, all logs in Codeigniter are stored in logs/ directory. To enable error logging you must set the “threshold†for logging in application/config/config.php. Also, your logs/ must be writable.
$config['log_threshold'] = 1;
34) How many types of messages can you log in Codeigniter?
There are three message types in Codeigniter. They are :
Error Messages. These are actual errors, such as PHP errors or user errors.
Debug Messages. These are messages that assist in debugging. For example, if a class has been initialized, you could log this as debugging info.
Informational
Messages. These are the lowest priority messages, simply giving information regarding some process.
35) How to set csrf token in codeIgniter?
Csrf is used to set the protection in CodeIgniter. To set csrf, you have to put the corresponding config value True.
Syntax: $config['csrf_protection'] = TRUE;
SOURCE: https://www.onlineinterviewquestions.com/codeigniter-interview-questions/
################################ CODEIGNITER ###################################
A Quick Overview of CodeIgniter
CodeIgniter Interview Questions
CodeIgniter is a PHP open-source web development framework for building dynamic
websites. Based on the MVC development pattern, Codeigniter can be modified to use the HMVC pattern. This pattern allows developers to maintain controller, view, and models in a sub-directory format. This framework is known for its higher speed as compared to other PHP frameworks. If you are looking for Codeigniter interview questions, we can help you!
A Quick Overview of CodeIgniter What is Codeigniter? It is a PHP open-source web development framework for building dynamic websites. Based on the MVC development pattern, Codeigniter can be modified to use the HMVC pattern. Latest Version 4.0, released on September 3, 2019 Stable Version 3.1.10, released on January 16, 2019
Created By EllisLab Written in PHP License MIT License Official Website https://codeigniter.com
Best CodeIgniter Interview Questions And Answers
Q. 1.What is Codeigniter & why it is used for?
It is a PHP open-source web development framework which is used for building dynamic websites.
Is this helpful? Yes No
suggest an answer 0 Answer
27 1
Q. 2.What is the latest version of Codelgniter? Lists its new features.
4.0 is the latest version of the Codelgniter framework. This version is released on September 3, 2019.
Here are some new features that support
Codelgniter
URL Helper
Query builder
Email Library
Form Validation Library
Session Library
Codelgniter updated these modules to enhance features.
Also Read: PHP interview questions
Is this helpful? Yes No
suggest an answer 0 Answer
15 1
Q. 3.List the databases supported by Codeigniter?
Currently Codeigniter supports these databases that's are given below :-
MySQL
Oracle
PostgreSQL
SQLite
ODBC
Firebird etc
Is this helpful? Yes No
suggest an answer 0 Answer
11 2
Q. 4.What is
hooks and how we can configure hooks in CodeIgniter?
It is a type of events which can be called before and after the execution of a program in CodeIgniter. For example Hooks can be used where we need to check whether a user is logged in or logged out before the execution of controller.
It can be globally enabled or disabled by setting in the application/config/config.php page
It can be defined in application/config/hooks.php page. In CodeIgniter each hook is specified like an array with this prototype:
Is this helpful? Yes No
suggest an answer 0 Answer
5 1
Q. 5.How to add or load a model
in CodeIgniter?
You can do it with this $this->load->model("ModelName");
Is this helpful? Yes No
suggest an answer 0 Answer
6 1
Q. 6.How to load a view in CodeIgniter?
You can use this $this->load->view('name'); to load a view in CodeIgniter.
Is this helpful? Yes No
suggest an answer 0 Answer
4 2
Q. 7.What is the default controller used in CodeIgniter? How we can change it?
In CodeIgniter when a specified file in the default controller loaded by default when there is no file name mentioned in URL. By default
"welcome.php" file is loaded after installing CodeIgniter.
Yes, we can change it from application/config/routes.php. We have to pass our controller name which we want to load by default in $route['default_controller']
For example, now the frontend is the default controller $route['default_controller'] = 'Frontend'; from now. Interview questions on Codeigniter are always a level up and thus a little tough to crack.
Is this helpful? Yes No
suggest an answer 0 Answer
2 1
Q. 8.Explain the basic Url Structure in Codeigniter?
The basic URL structure is
bestinterviewquestion.com/class/function/ID.
Here class represents controller's class that needs to be invoked.
Here "function" is name of method which is called.
ID is an additional parameter that is passed to controllers.
Is this helpful? Yes No
suggest an answer 0 Answer
6 0
Q. 9.What do you mean by helper in CodeIgniter?
Helpers is collection of functions which help us with different tasks as name suggested. Every helper function is used to performs specific task with no dependence on other functions.
CodeIgniter provide various types of helper class like url_helper, captcha_helper ,email_helper. All these helpers are located in system/helper.
By default CodeIgniter does not load any Helper files. First step is to be load Helper. After loaded it is available in all controller and views.
How we can load a Helper : $this->load->helper('name');
Here
"name" is file name of helper.
How to load multiple Helpers at one time.
$this->load->helper(array('helper1', 'helper2', 'helper3')); // Here helper1,helper2,helper3 are different helper's name.
Is this helpful? Yes No
suggest an answer 0 Answer
3 0
Q. 10.Explain the difference between helper and library in CodeIgniter?
Helper is a set of Common functions which we can use within Models, Views, Controllers everywhere. Once we include that file then we can get access to the functions.
Library is a class which we need to make an instance of the class by $this->load->library() this
function.
NOTE : A library is used in object-oriented context but a helper is more suitable to be used within the Views
Also Read: Laravel interview questions
Is this helpful? Yes No
suggest an answer 0 Answer
3 0
Q. 11.What do you mean by Get_instance in CodeIgniter?
It is a globally available methods or functions that returns the Controller super-object which contains all the currently loaded classes. get_instance() function returns the Controller class instance.
Is this helpful? Yes No
suggest an answer 0 Answer
1 1
Q. 12.What do
you mean by routing in Codeigniter?
It is the process of taking a URI endpoint and decomposing it into parameters to determine module controller and action of that controller should receive the request.
CodeIgniter has a userfriendly URI routing rule so that we can re-route URL easily . There is a one-to-one relationship between a URL string and its corresponding controller class and its methods.
Routing is a technique through which we can converts SEO friendly URLs into a server code format that easily understandable.
We can manage these from
routes.php file at the located in application/config.
Is this helpful? Yes No
suggest an answer 0 Answer
1 0
Q. 13.List some different hook point in Codeigniter?
Codeigniter supports various hook points.
post_controller_constructor
pre_controller
post_sytem
pre_system
cache_override
display_override
post_controller
If you are scrolling on the web for Codeigniter interview questions for 2 year experience pdf, then this guide will gonna help you.
Is this helpful? Yes No
suggest an answer 0 Answer
3
1
Q. 14.How to link images/CSS/JavaScript from a view in codelgniter?
We can use an absolute path to resources to link images/CSS/JavaScript from a view in CodeIgniter.
For Example :
<link rel = "stylesheet" type = "text/css" href = "<?php echo base_url(); ?>css/responsive.css">
<script type = 'text/javascript' src = "<?php echo base_url(); ?>js/jquery.js"></script>
Is this helpful? Yes No
suggest an answer 0 Answer
2 0
Q. 15.What do you mean by inhibitor in CodeIgniter?
Inhibitor is an error handling class.
It is using the native PHP functions like set_error_handler, set_exception_handler, register_shutdown_function to handle all error's like parse errors, exceptions, and fatal errors.
Is this helpful? Yes No
suggest an answer 0 Answer
3 0
Q. 16.How to remove index.php from URL in Codeigniter?
You can follow these given steps to remove index.php from URL in Codeigniter.
Please open config.php and change from $config['index_page'] = "index.php" to $config['index_page'] = "";
Update also from $config['uri_protocol'] ="AUTO"; to $config['uri_protocol'] = "REQUEST_URI";
Put this code in your htaccess
file
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Is this helpful? Yes No
suggest an answer 0 Answer
3 0
Q. 17.What is CSRF and how you can enable CSRF in CodeIgniter?
In codeIgniter CSRF token is a random generated value that changes with each HTTP request sent by webform. When the form is submitted by user then website checks this submitted CSRF token equals or not the saved in the session.
We can enable CSRF protection from config.php and update the
following values
$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'csrf_test_name'; //The token name
$config['csrf_cookie_name'] = 'csrf_cookie_name'; //The cookie name
$config['csrf_expire'] = 7200; // It will expire after this given time.
Is this helpful? Yes No
suggest an answer 0 Answer
1 0
Q. 18.How to extend the class in Codeigniter?
You have to build a file with name application/core/Blog.php and declare your class with
Class Blog extends CI_Input {
// Write your code here
}
Is this helpful?
Yes No
suggest an answer 0 Answer
2 0
Q. 19.What is Codeigniter Library and how we can load it?
Codeigniter provides a rich set of libraries, which indirectly increase the speed of developing an application. These Codeigniter system library is located in system/libraries.
In Codeigniter the library can be loaded with $this->load->library('class name');
If we want to load multiple libraries then we can use like $this->load->library(array('comment', 'blog'));
Related Article: Wordpress interview questions
Is this helpful? Yes No
suggest an answer 0
Answer
2 0
Q. 20.How to handle sessions in Codeigniter?
How to add values in session in Codeigniter
$_SESSION['username'] = 'bestinterviewquestion.com' // It can be use in core PHP
$this->session->set_userdata('username', 'bestinterviewquestion.com'); // It can be done in Codeigniter
We can pass array to store values in session in Codeigniter.
$array = array(
'username' => 'bestinterviewquestion.com',
'email' => 'info@bestinterviewquestion.com',
'url' =>
'https://www.bestinterviewquestion.com'
);
$this->session->set_userdata($array);
How to remove values in session in Codeigniter
unset($_SESSION['username']); // It can be use in core PHP
$this->session->unset_userdata('username'); // It can be done in Codeigniter
If we want to remove more values from session then we can use like this
$this->session->unset_userdata($array); // $array is defined above. It is an array with key & values.
How to get data from session in Codeigniter
$this->session->userdata('username'); // Here we will get
username, if it is exists in session.
Is this helpful? Yes No
suggest an answer 0 Answer
3 0
Q. 21.Explain why codeigniter is called as loosely based mvc framework?
It is called as loosely based mvc framework because in codeigniter controller is the necessary but model and view are optional. It means we can build a website without model.
Is this helpful? Yes No
suggest an answer 0 Answer
2 0
Q. 22.How to install CodeIgniter? Explain step by step.
CodeIgniter can be installed with four steps that are given below:
Download it from its download
page & then unzip the package.
Upload its files and folders on your server or localhost.
Open application/config/config.php file and set base URL.
If you want to use database then open application/config/database.php file and set your database credientails.
Now it's installed
If you want to configure additional setting then you can click here
Is this helpful? Yes No
suggest an answer 0 Answer
1 0
Q. 23.What are the server requirements to install codeigniter?
We need only PHP version 5.6 or greater than 5.6. because of potential security and performance issues.
Is this
helpful? Yes No
suggest an answer 0 Answer
2 0
Q. 24.How we can load multiple helper files in Codelgniter?
You have to pass your helpers in array form. Here helper_1, helper_2, helper_3, helper_4 are different helpers that we want to load.
$this->load->helper(
array('helper_1', 'helper_2', 'helper_3', 'helper_4')
);
Is this helpful? Yes No
suggest an answer 0 Answer
1 0
Q. 25.How we can enable hooks in CodeIgniter?
If you want to enable hooks then you have to enabled/disabled by setting in the application/config/config.php
file.
If you want to enable hooks then use this $config['enable_hooks'] = TRUE;
Is this helpful? Yes No
suggest an answer 0 Answer
0 0
Q. 26.What do you mean by drivers and how we can create in CodeIgniter?
In CodeIgniter drivers are a very special type of Library that has a parent class and its child classes. Child classes have the access to its parent class but not their siblings. It provides an elegant syntax in your controllers file for libraries.
It can found in the system/libraries/ directory.
If we want to use a driver we have to initialize it within
a controller with this given method.
$this->load->driver('class_name');
Here class_name is the name of the driver class which we want to invoke.
How we can create our own drivers in CodeIgniter.
You can create your own driver folder in /application/libraries/
Create your_Your_Driver_name.php file in /application/libraries/Your_Driver
In /application/libraries/Your_Driver/drivers
Your_Driver_name_subclass_1.php
Your_Driver_name_subclass_2.php
Is this helpful? Yes No
suggest an answer 0 Answer
1 0
Q. 27.How we can print SQL statement in codeigniter
model?
You can use $this->db->last_query(); to display the query string.
You can use print_r($query); to display the query result.
Is this helpful? Yes No
suggest an answer 0 Answer
2 0
Q. 28.Explain how to create custom 404 page in CodeIgniter?
You can create your custom 404 page with these steps. Please follow these steps one by by.
You have to update your own created controller's class with $route['404_override'] = 'Controller_Class_Name';. You have to update this in your application/config/routes.php
Please create your new controller
"Controller_Class_Name" file in your controllers directory application/controllers/.
Please put this code in your Controller_Class_Name.php
class Controller_Class_Name extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$this->output->set_status_header('404');
$this->load->view('error_page_404');
}
}
Now create your "error_page_404" view file.
Is this helpful? Yes
No
suggest an answer 0 Answer
3 0
Q. 29.How to insert data into database in codeigniter?
You can use $this->db->insert(); to insert data in your database in Codeigniter.
Also Read: Symfony interview questions
Example
If you want to insert this in your "Admin Table".
$dataArray = array(
'name'=>'bestinterviewquestion.com',
'phone'=>'9971083635',
'email'=>'info@bestinterviewquestion.com'
);
$this->db->insert('Admin',$dataArray);
// Here "Admin" is My TableName
Is this helpful? Yes No
suggest an answer 0 Answer
1 0
Q. 30.How to get
last inserted id in codeigniter?
You can use $lastInsertID = $this->db->insert_id(); after insert query.
Is this helpful? Yes No
suggest an answer 0 Answer
0 0
Q. 31.How to write join query in CodeIgniter?
$this->db->join('blog', 'comment.blog_id= blog.id', 'inner');
OR
$this->db->join('blog', 'comment.blog_id= blog.id');
Is this helpful? Yes No
suggest an answer 0 Answer
0 1
Q. 32.Explain how to set and get config item value in Codeigniter?
To set config value
$this->config->set_item('mainURL','bestinterviewquestion.com'); we can use this.
To get config value $this->config->set_item('mainURL'); we can use this.
Is this helpful? Yes No
suggest an answer 0 Answer
0 0
Q. 33.How we can get Ip address in Codeigniter?
You can use $this->input->ip_address(); this to get IP Address.
Is this helpful? Yes No
suggest an answer 0 Answer
1 1
Q. 34.How we can get current method or controller in Codeigniter?
You can use this $this->router->fetch_class(); to get current controller
name.
You can use this $this->router->fetch_method(); to get current method.
Is this helpful? Yes No
suggest an answer 0 Answer
0 0
Q. 35.How to use Pagination in Codelgniter?
Is this helpful? Yes No
suggest an answer 0 Answer
0 2
Q. 36.How to use delete query in Codeigniter?
You can use $this->db->delete('admin', array('id' => 5)); this query to delete record according to condition
// DELETE FROM admin WHERE id = 5
Is this helpful? Yes No
suggest an answer 0 Answer
1 0
Q. 37.How to truncate
table with query in Codelgniter?
// TRUNCATE table admin;
You can use this to truncate table
$this->db->from('admin'); // select admin table
$this->db->truncate(); // truncate admin table
OR
You can also use like this
$this->db->truncate('admin'); // truncate admin table
Is this helpful? Yes No
suggest an answer 0 Answer
1 0
Q. 38.How to enable error log in CodeIgniter?
Step 1. Make /application/logs log folder writable
Step 2. Set $config['log_threshold'] = 1; in /application/config/config.php
Is this helpful?
Yes No
suggest an answer 0 Answer
1 0
Q. 39.How we can redirect a page in CodeIgniter?
We can use the redirect() function to redirect on any page.
Example
$this->load->helper('url'); // Firstly you have to load url helper.
if (condition != TRUE) {
redirect('login_page');
}
Is this helpful? Yes No
suggest an answer 0 Answer
0 1
Q. 40.How we can connect multiple databases in CodeIgniter?
$database1 = $this->load->database('DB1', TRUE); // Connect with database 1
$database2 = $this->load->database('DB2', TRUE); // Connect with database 2
Is this helpful? Yes No
suggest an answer 0 Answer
1 0
History of Codeigniter
The first version was released in Feb 2006 by
EllisLab.
Advantages of Codeigniter
If you are preparing for Codeigniter interview questions, do memorize the powers of CodeIgniter.
Easy to learn, handle and customize
Flexible and easy to configure
Amazing Active Record Implementation
Best-in-class documentation
Discount, Offers, Coupons and Options and Properties
Extensive user base
SOURCE: https://www.bestinterviewquestion.com/codeigniter-interview-questions
########################################### CODEIGNITER ###########################################
1) Explain what is CodeIgniter?
Codeigniter is
an open source framework for web application. It is used to develop websites on PHP. It is loosely based on MVC pattern, and it is easy to use compare to other PHP framework.
2) Explain what are hooks in CodeIgniter?
Codeigniter’s hooks feature provides a way to change the inner working of the framework without hacking the core files. In other word, hooks allow you to execute a script with a particular path within the Codeigniter. Usually, it is defined in application/config/hooks.php file.
3) Explain how you will load or add a model in CodeIgniter?
Within your controller functions, models will typically
be loaded; you will use the function
$this->load->model (‘Model_Name’);
4) Explain what helpers in CodeIgniter are and how you can load a helper file?
In CodeIgniter, helpers are group of function in a particular category that assist you to perform specific functions. In CodeIgniter, you will find many helpers like URL helpers- helping in creating links, Text helpers- perform various text formatting routines, Cookies- helpers set and read cookies. You can load helper file by using command $this->load->helper (‘name’) ;
5) Explain routing in Codeigniter?
In
CodeIgniter, the way PHP files served is different rather than accessing it directly from the browser. This process is called routing. Routing in CodeIgniter gives you freedom to customize the default URL pattern to use our own URL pattern according to the requirement. So, whenever there is a request made and matches our URL pattern it will automatically direct to the specified controller and function.
codeigniter
6) Why is there a need to configure the URL routes?
Changing the URL routes has some benefits like
From SEO point of view, to make URL SEO friendly and get more user visits
Hide
some URL element such as a function name, controller name, etc. from the users for security reasons
Provide different functionality to particular parts of a system
7) List out different types of hook point in Codeigniter?
Different types of hook point in Codeigniter includes
post_controller_constructor
pre_controller
post_sytem
pre_system
cache_override
display_override
post_controller
8) Mention what are the security parameter for XSS in CodeIgniter?
Codeigniter has got a cross-site scripting hack prevention filter. This filter either runs automatically or you can run
it as per item basis, to filter all POST and COOKIE data that come across. The XSS filter will target the commonly used methods to trigger JavaScript or other types of code that attempt to hijack cookies or other malicious activity. If it detects any suspicious thing or anything disallowed is encountered, it will convert the data to character entities.
9) Explain how you can link images/CSS/JavaScript from a view in code igniter?
In HTML, there is no Codeigniter way, as such it is a PHP server side framework. Just use an absolute path to your resources to link images/CSS/JavaScript from a view in
CodeIgniter
/css/styles.css
/js/query.php
/img/news/566.gpg
10) Explain what is inhibitor in CodeIgniter?
For CodeIgniter, inhibitor is an error handler class, using the native PHP functions like set_exception_handler, set_error_handler, register_shutdown_function to handle parse errors, exceptions, and fatal errors.
11) Mention what is the default URL pattern used in Codeigniter framework?
Codeigniter framework URL has four main components in default URL pattern. First we have the server name and next we have the controller class name followed by controller function name and function parameters at the end. Codeigniter can be accessed using the URL helper. For example
http://servername/controllerName/controllerFunction/parameter1/parameter2.
12) Explain how you can extend the class in Codeigniter?
To extend the native input class in CodeIgniter, you have to build a file named application/core/MY_Input.php and declare your class with
Class MY_Input extends CI_Input {
}
13) Explain how you can prevent CodeIgniter from CSRF?
There are several ways to protect CodeIgniter from CSRF, one way of doing is to use a hidden field in each form on the website. This hidden field is referred as CSRF token; it is nothing but a random value that alters
with each HTTP request sent. As soon as it is inserted in the website forms, it gets saved in the user’s session as well. So, when the form is submitted by the users, the website checks whether it is the same as the one saved in the session. If it is same then, the request is legitimate.
14) Explain how you can enable CSRF (Cross Site Request Forgery) in CodeIgniter?
You can activate CSRF (Cross Site Request Forgery) protection in CodeIgniter by operating your application/config/config.php file and setting it to
$config [ ‘csrf_protection’] = TRUE;
If you avail the form helper, the
form_open() function will insert a hidden csrf field in your forms automatically
SOURCE: https://career.guru99.com/top-14-codeigniter-interview-questions/
######################################### CODEIGNITER ############################################
Codeigniter Interview Questions and Answers for 2 Year Experience
mytectra.com
BY ANURADHA
March 26, 2018 in INFORMATION TECHNOLOGIES (IT) 1 Comment 16358
1.what is the Codeigniter?
Codeigniter is open source, webapplication a PHP framework. Codeigniter is loosely based on MVC pattern simple framework in
php.
2.When and who developed codeigniter?
The first public version of CodeIgniter was released on February 28, 2006.
3.What is the current version of codeigniter?
The lastest version 2.2.0 till 6-05-2014.
4. Explain Application Flow Chart in codeigniter.
Application flow chart from Codeigniter documentaion
The index.php serves as the front controller, initializing the base resources needed to run CodeIgniter.
2. The Router examines the HTTP request to determine what should be done with it.
If a cache file exists, it is sent directly to the browser, bypassing the normal system
execution.
Security. Before the application controller is loaded, the HTTP request and any user submitted data is filtered for security.
The Controller loads the model, core libraries, helpers, and any other resources needed to process the specific request.
The finalized View is rendered then sent to the web browser to be seen. If caching is enabled, the view is cached first so that on subsequent requests it can be served.
5.Explain how you can extend the class in Codeigniter?
To extend the native input class in CodeIgniter, you have to build a file named application/core/MY_Input.php and declare your class with
Class MY_Input extends CI_Input
{
}
6. what are the features of codeigniter?
1. codeigniter is open source, webapplication framework.
2.codeigniter is light weight framework.
3.codeigniter faster than any other farmework.
4.codeigniter search engine friendly urls generator.
5.codeigniter is easy exensible.
7. List out different types of hook point in Codeigniter?
Different types of hook point in Codeigniter includes
post_controller_constructor
pre_controller
post_sytem
pre_system
cache_override
display_override
post_controller
8. Explain MVC in
Codeigniter.
Model–View–Controller (MVC) is an architecture that separates the representation of information from the user’s interaction with it.
Controller:- The Controller serves as an intermediary between the Model, the View. controller mediates input, converting it to commands for the model or view.
Model:-The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert, and update information in your database.The model consists of application data and business rules.
View:-The View is the information that is being presented to a user. A View
will normally be a web page.A view can be any output representation of data.
For more detail understanding MVC please read this article What is MVC(Model-View-Controller) Architecture.
9. Explain codeigniter file structure.
Application
-cache
-config
-controllers
-core
-errors
-helpers
-hooks
-languages
-logs
-models-
-thirdparty
-view
system
-core
-database
-fonts
-helpers
-language
-libraries
10. Explain what is meant by inhibitor in Codeigniter?
For CodeIgniter, inhibitor is an error handler class that use
native PHP functions like set_exception_handler, set_error_handler, register_shutdown_function to handle parse errors, exceptions, and fatal errors.
11. What are the hooks in codeigniter?
In CodeIgniter, hooks are events which can be called before and after the execution of a program. It allows executing a script with specific path in the CodeIgniter execution process without modifying the core files. For example, it can be used where you need to check whether a user is logged in or not before the execution of controller. Using hook will save your time in writing code multiple times.
There are two hook files in CodeIgniter. One is
application/config/hooks.php folder and other is application /hooks folder.
In other language, if you want to run a code every time after controller constructor is loaded, you can specify that script path in hooks.
he hooks feature can be globally enabled/disabled by setting the following item in the application/config/config.php file:
$config[‘enable_hooks’] = TRUE;
Hooks are defined in application/config/hooks.php file.For example
$hook[‘pre_controller’] = array(
‘class’ =>
‘MyClass’,
‘function’ => ‘Myfunction’,
‘filename’ => ‘Myclass.php’,
‘filepath’ => ‘hooks’,
‘params’ => array(‘test’, ‘test1’, ‘webs’)
);
12.Explain what is meant by routing in Codeigniter?
In CodeIgniter, the way PHP files served is in different rather than accessing it directly from the browser. This process is the called the routing. Routing in CodeIgniter gives you freedom to customize the default URL pattern to
use our own URL pattern according to the requirement. So, whenever there is a request made and matches our URL pattern it will be automatically direct to the specified controller and the function.
13. How you will be add or load an model in the codeigniter?
Models will be the typically loaded and called from within your controller functions. To load a model you will have to use the following function:
$this->load->model(‘Model_name’);
14.Why is there a need to configure the URL routes?
Changing the URL routes has some benefits like
From the SEO point of the view, to make
URL SEO friendly and get more user visits
Hide some URL element such as the function name, controller name, etc. from the users for the security reasons
Provide different functionality to the particular parts of a system
15. Which are the helpers in the codeigniter?
Helpers, as the name suggests, help you with tasks. Each helper file is simply a collection of the functions in a particular category.There are URL Helpers, that assist in creating links, there are Form Helpers that help you create form elements, Text Helpers perform various text formatting routines, Cookie Helpers set and read cookies, File Helpers help you deal with the files,
etc.
Loading a helper file is quite simple using the following function:
$this->load->helper(‘name’);
16. Mention which are the security parameter for XSS in the CodeIgniter?
Codeigniter has got a cross-site scripting hack prevention filter. This filter either runs automatically or you can run it as per item basis, to filter all the POST and COOKIE data that come across. The XSS filter will target the commonly used methods to trigger JavaScript or other types of code that attempt to hijack cookies or other malicious activity. If it detects any suspicious thing or anything disallowed is encountered, it
will convert the data to character entities.
17.How can you load the multiple helper files?
To load multiple helper files, specify them in an array,
$this->load->helper(array(‘helper1’, ‘helper2’, ‘helper3’));
18. Explain how you can link images/CSS/JavaScript from a view in the codeigniter?
In HTML, there is no Codeigniter way, as such it is a PHP server side framework. Just use an absolute path to your resources to link the images or CSS or JavaScript from a view in
CodeIgniter
/css/styles.css
/js/query.php
/img/news/566.gpg
19.Explain CodeIgniter library. How will you load it?
CodeIgniter provides a rich set of libraries. It is an essential part of CodeIgniter as it increases the developing speed of an application. It is located in the system/library.
It can be loaded as follows,
$this->load->helper(array(‘helper1’, ‘helper2’, ‘helper3’));
20.Mention what is the default URL pattern used in Codeigniter framework?
Codeigniter framework URL has four main components in default URL pattern.
First we have the server name and next we have the controller class name followed by controller function name and function parameters at the end. Codeigniter can be accessed using the URL helper. For example http://servername/controllerName/controllerFunction/parameter1/parameter2.
SOURCE: https://www.mytectra.com/interview-question/codeigniter-interview-questions-and-answers-for-2-year-experience/
########################################## CODEIGNITER ###########################################
CODEIGNITER INTERVIEW QUESTIONS & ANSWERS
CodeIgniter Interview Questions
Are you in search of CodeIgniter Jobs? Then you are at the
right place. We provide you with the complete CodeIgniter interview Question and Answers on our page. CodeIgniter is an open-source software rapid development web framework, for use in building dynamic web sites with PHP. CodeIgniter is loosely based on the popular model–view–controller (MVC) development pattern. There are numerous leading companies that offer various job positions in CodeIgniter like PHP Developer with CodeIgniter Frame work, Senior PHP Developer, Backend Developer CodeIgniter and many more. To clear any interview, you must prepare well for interview, so we provide a complete and tricky Interview questions on our page. To know more about interview question and
answers and for various positions in Coded Ui visit our website Wisdomjobs.com.
CodeIgniter Interview Questions And Answers Prev Next CodeIgniter Interview Questions
Codeigniter Tutorial
Codeigniter Practice Test
Codeigniter Pragnya Meter Exam
CodeIgniter Jobs
All Interview Questions
Question 1. What Is Codeigniter?
Answer :
Codeigniter is an open source framework for web application on PHP. It is loosely based on MVC pattern and it is similar to CakePHP.
Question 2. What Are The Most Prominent Features Of
Codeigniter?
Answer :
A list of most prominent features of CodeIgniter:
It is an open source framework and free to use.
It is extremely light weighted.
It is based on Model View Controller (MVC) pattern.
It has full featured database classes and support for several platforms.
It is extensible. You can easily extend system by using your own libraries, helpers etc.
Excellent documentation.
PHP Interview Questions
Question 3. Explain Codeigniter Architecture?
Answer :
From technical point of view, CodeIgniter is dynamically instantiation (light-weighted),
loosely coupled (components rely very less on each other) and has component singularity (each class and functions are narrowly focused towards their purpose).
Question 4. How Can You Add Or Load A Model In Codeigniter?
Answer :
To load models in controller functions, use the following function:
$this->load->model('ModelName');
PHP Tutorial
Question 5. How Can You Connect Models To A Database Manually?
Answer :
To connect database manually use following syntax,
$this->load->database();
MySQL Interview Questions
Question 6. Explain Views In Codeigniter?
Answer :
View folder contains all the markup files like header, footer, sidebar, etc. They can be reused by embedding them anywhere in controller file. They can't called directly, they have to be loaded in the controller's file.
Question 7. How Can You Load A View In Codeigniter?
Answer :
View can't be accessed directly. It is always loaded in the controller file.
Following function is used to load a view
page:
$this->load->view('page_name');
MySQL Tutorial PHP+MySQL Interview Questions
Question 8. Explain Controller In Codeigniter?
Answer :
A controller is the intermediary between models and views to process HTTP request and generates a web page. It is the center of every request on your web application.
Question 9. What Is Basic Codeigniter Url Structure?
Answer :
Instead of using 'query-string' approach, it uses a segment based approach.
Its structure is as
follows,
abc.com/class/function/ID
class represents controller class that needs to be invoked.
function is the method that is called.
ID is any additional segment that is passed to controllers.
Drupal Interview Questions
Question 10. What Is The Default Method Name In Codeigniter?
Answer :
By default controller always calls index method. If you want to call a different method, then write it in the controller?s file and specify its name while calling the function.
Drupal Tutorial
Question 11. Explain Remapping Method Calls
In Codeigniter?
Answer :
Second segment of URI determines which method is being called. If you want to override it, you can use _remap() method. The _remap method always get called even if URI is different. It overrides the URI
MYSQL DBA Interview Questions
Question 12. What Is Helper In Codeigniter? How Can You Load A Helper File?
Answer :
Helpers are the group of functions in a particular category that assist you to perform specific functions.
In CodeIgniter, there are many helpers like:
URL Helpers: helping in creating links.
Text
Helpers: perform various text formatting routines.
Cookies Helpers: set and read cookies.
To load helper file, use the following command:
$this->load->model('ModelName');
PHP Interview Questions
Question 13. Explain Codeigniter Library. How Will You Load It?
Answer :
CodeIgniter provides a rich set of libraries. It is an essential part of CodeIgniter as it increases the developing speed of an application. It is located in the system/library.
It can be loaded as
follows,
$this->load->library('class_name');
WordPress Tutorial
Question 14. How Can You Create A Library In Codeigniter?
Answer :
There are three methods to create a library:
Creating an entire new library
Extending native libraries
Replacing native libraries
Question 15. What Is Stable Version Of Codeigniter?
Answer :
Version: 3.0.5,
Date January 13, 2016
PHP5 Interview Questions
Question 16. In Which Language Codeigniter Is Written?
Answer
:
PHP
Joomla Tutorial
Question 17. What Are The Features Of Codeigniter? Open Source Framework?
Answer :
Light Weight
CodeIgniter is Extensible
Full Featured database classes
WordPress Interview Questions
Question 18. How To Access Config Variable In Codeigniter?
Answer :
$this->config->item(‘variable name’);
MySQL Interview Questions
Question 19. How To Unset Session In Codeigniter?
Answer
:
$this->session->unsetuserdata(‘somename’);;
CakePHP Tutorial
Question 20. Explain Codeigniter File Structure?
Answer :
following are the folder structure :-
application:
cache
Config
Controllers
core
errors
helpers
hooks
language
libraries
logs
models
thirdparty
views
system:
core
database
fonts
helpers
language
libraries
Joomla Interview Questions
Question 21. Explain Application Flow Chart
In Codeigniter?
Answer :
The following graphic illustrates how data flows throughout the system:
CodeIgniter application flow:
The index.php serves as the front controller, initializing the base resources needed to run CodeIgniter.
The Router examines the HTTP request to determine what should be done with it.
If a cache file exists, it is sent directly to the browser, bypassing the normal system execution.
Security. Before the application controller is loaded, the HTTP request and any user submitted data is filtered for security.
The Controller loads the model, core libraries, helpers, and any
other resources needed to process the specific request.
The finalized View is rendered then sent to the web browser to be seen. If caching is enabled, the view is cached first so that on subsequent requests it can be served.
Question 22. Explain Mvc In Codeigniter?
Answer :
CodeIgniter is based on the Model-View-Controller development pattern. MVC is a software approach that separates application logic from presentation. In practice, it permits your web pages to contain minimal scripting since the presentation is separate from the PHP scripting.
The Model represents your data structures. Typically your model classes will
contain functions that help you retrieve, insert, and update information in your database.
The View is the information that is being presented to a user.
A View will normally be a web page, but in CodeIgniter, a view can also be a page fragment like a header or footer. It can also be an RSS page, or any other type of “pageâ€.
The Controller serves as an intermediary between the Model, the View, and any other resources needed to process the HTTP request and generate a web page.
CodeIgniter Tutorial
Question 23. Can You Extend Native Libraries In Codeigniter?
Answer :
Yes, we can add some extended functionality
Q2. Explain the CodeIgniter hooks features?
Answer:
This is the basic CodeIgniter Interview Questions asked in an interview. The CodeIgniter’s Hooks feature is mainly implemented to update the inner core functionalities of the framework and this is performed without any interventions to core files in the frameworks. Find below few different available hook points implemented in CodeIgniter.
Popular Course in this category
Sale
All in One Software Development Bundle (600+ Courses, 50+ projects)
600+ Online Courses | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (3,144 ratings)Course Price
₹12999
₹150000
View Course
Related Courses
Python Certification Training (36 Courses, 13+ Projects)Java Training (40 Courses, 29 Projects)Programming Languages Training (41 Courses, 13+ Projects)
Pre_controller: It is normally called prior to all the called or associated controllers
Pre_system: It is generally called during the system execution process.
Post_controller: It is called exactly after the completion of the controller execution.
Post_controller_construcor: It is called after the initiation of the controller execution but prior to any method calls processing.
Display_override: It is initiated to override the display
method.
Post_system: This is called after the end of the system execution phase and after the final page and associated data is processed to the web page.
Q3. Explain different functions used in CodeIgniter?
Answer:
Find below few important functions used in CodeIgniter.
is_https()
get_mimes()
html_escape(var)
config_item(key)
is_php(version)
is_cli()
Let us move to the next CodeIgniter Interview Questions.
Q4. Explain the importance of CLI in CodeIgniter?
Answer:
CLI is basically a text-based command line interphase which is used for the interaction purpose by executing a set of
commands. Find below few important uses of CLI.
Cronjobs can be executed without using wget or curl.
It is used to incorporate CodeIgniter with the other programming languages.
It can be implemented to set platforms, permissions, run caches, and other interrelated tasks.
Q5. What do you mean by the inhibitor in CodeIgniter?
Answer:
Inhibitors are basically error handling classes that are associated with CodeIgniter and these are implemented using different PHP functions. Find below a few different PHP functions that are implemented for the same.
Set_error_handler
Set_exception_handler
Register_shutdown_function
etc.
Part 2 – CodeIgniter Interview Questions (Advanced)
Let us now have a look at the advanced CodeIgniter Interview Questions.
Q6. Explain the routing in CodeIgniter?
Answer:
Routing is mainly implemented to define the URLs according to the defined requirements. It can be defined in two ways. These are Wildcards and Regular Expressions.
Wildcards: It can also be classified into two ways.
: any – This is used for the series that consists of only matched characters.
: num – This is used for the series that consists of only matched numbers.
Regular Expressions: This is mainly
implemented to redirect routes. In case of CodeIgniter, own regular expressions can be created and implemented to run and execute the URLs.
Q7. What do you mean by CodeIgniter Library?
Answer:
The CodeIgniter provides a different set of libraries and these are useful with the continues improvements and support of the application and also its corresponding enhancements. This is mainly located in the system->library section. There are different types of methods that can be used to create a library.
The process to create a whole new library.
The process to replace the native library.
The process to extend the native library.
Let us move
to the next CodeIgniter Interview Questions.
Q8. Explain different features implemented by CodeIgniter?
Answer:
There are different features implemented in the CodeIgniter framework and those are used to implement the web solutions in a more convenient manner. Find below few important features of the same.
The framework used in this case does have a small footprint.
The solutions provided through this framework normally traverses through the different library files and these help in producing easier and more simpler solutions in case of different critical and complex scenarios.
It goes through different layers of security patches
and thus it is considered to be a much-secured framework from the developer perspective.
Due to the different inbuilt and created library files, it does provide much swift and convenient output and performances from the end user perspective.
Q9. Explain the helper files in CodeIgniter?
Answer:
This is the most popular CodeIgniter Interview Questions asked in an interview. Helper files are generally used to help the implementation of different tasks through the CodeIgniter frameworks. These helper files are mainly consisting of a different function of specific categories. These files are used to perform those tasks without hampering other methods and functions. These
are also no dependency exists for the other functions. CodeIgniter doesn’t load any helper files by default and to use this feature, helper files need to be loaded initially. After the successful loading, it becomes globally available and accessible through different controllers and views. These files are generally used to get stored in the system/helpers directory.
Q10. Explain the advantages of using CodeIgniter framework?
Answer:
Find below few important advantages of using CodeIgniter.
It goes through different layers of security patches and thus it is considered to be a much-secured framework from the developer
perspective.
It is fast, reliable and lightweight and thus becomes more capable from the end user perspective.
It provides extensive support across different library files.
It provides extensive support across different database providers.
In the case of PHP development, CodeIgniter proves to be a better choice due to its smart affordability and use of different library and helper files.
Recommended Articles
This has been a guide to list Of CodeIgniter Interview Questions and Answers so that the candidate can crackdown these CodeIgniter Interview Questions easily. Here in this post, we have studied top CodeIgniter Interview Questions which are
often asked in interviews. You may also look at the following articles to learn more –
C# Interview Questions and Answers
GIT Interview Questions
SASS Interview Questions
Graphic Design Interview Questions
Capex vs Opex: What are the benefits
Overview of PHP Math Functions
SOURCE: https://www.educba.com/codeigniter-interview-questions/
###################################### CODEIGNITER ########################################
CodeIgniter Interview Questions: CodeIgniter Interview Questions and Answers. CodeIgniter is an open-source, rapid development web framework, for use in
building dynamic websites written in PHP.
Codeigniter Interview Questions
CodeIgniter | CodeIgniter Interview Questions | Basic
Q:- What is CodeIgniter?
Codeigniter is a light-weight, open source, php framework. Codeigniter is loosely based on MVC pattern.
CodeIgniter is the most simplest framework in PHP, which is you will easily learn.
It's mostly known for its speed as compared to other frameworks in php.
Its goal is to enable you to develop projects much faster than you could if you were writing code from scratch, by providing a rich set of libraries for commonly needed tasks, as well as a simple interface and logical structure to access these
libraries.
Q:- When and who developed codeigniter?
CodeIgniter was created by EllisLab and is now a project of the British Columbia Institute of Technology. The first public version of CodeIgniter was released on February 28, 2006.
Q:- Which is the best PHP ORM for codeigniter?
DataMapper
An Object Relational Mapper written in PHP for CodeIgniter. It is designed to map your Database tables into easy to work with objects, fully aware of the relationships between each other.
Gas ORM
A lightweight and easy-to-use ORM for CodeIgniter. Gas was built specifically for CodeIgniter app. It uses CodeIgniter Database
packages, a powerful DBAL which support numerous DB drivers. Gas ORM provide a set of methods that will map your database tables and its relationship, into accessible object.
Doctrine
Doctrine Link
NOTE: You must do some workaround to integrate this with CI, try here.
You may also like - Core PHP Interview Questions
Q:- What are the features of codeigniter?
Following are the features of CodeIgniter:
It is free to use as for open source framework.
It is light weight. The core system requires only a few very small libraries. Not like other frameworks that require heavy file libraries.
CodeIgniter is Fast. It is faster than any
other framework in php.
The URLs generated by CodeIgniter are clean and search engine friendly. You will change any url to what ever you want from files.
CodeIgniter is Extensible. The system can be easily extended through the use of your own libraries, helpers, or through class extensions or system hooks.
CodeIgniter Uses MVC (Model View Controller) which allows great separation between logic and presentation.
CodeIgniter requires nearly zero configuration, does not require you to use the command line, not forced to learn a templating language.
Full Featured database classes with support for several platforms, Security and XSS Filtering, Error
Logging.
Q:- Helper vs. Library: CodeIgniter?
Helpers
are just small functions that help you avoid repetitive code and produce standard results. Whereas libraries contain classes, can include different files, talk to database etc.
Library
is used in object oriented context (Controller, …), while a helper is more suitable to be used within the Views (non object oriented).
Helper, Plugin and Library:
Since all three methods achieve the same ends. The question then is when do you use what?
Fortunately, CI has also provided that distinction in their user guide which you can go read it
yourself.
For me, these are my guidelines on when to use what:
1. Plugins –
I put all 3rd party codes I’m using in my application as Plugins. I would, as best as I can, try to use classes rather than straight function calls.
2. Helpers –
Any standalone straight functions calls, which are repetitive in nature, I classify them as Helpers. For example, sorting functions, my own calculation functions, etc
3. Libraries –
I classify my own classes as ‘Libraries’. Normally, if I’m already writing a class in my application, it would then to be the core logic of the
application, as such, I group them all in the Library folder.
Q:- Explain Application Flow Chart in codeigniter?
Application flow chart from Codeigniter documentaion
The index.php serves as the front controller, initializing the base resources needed to run CodeIgniter.
The Router examines the HTTP request to determine what should be done with it.
If a cache file exists, it is sent directly to the browser, bypassing the normal system execution.
Security. Before the application controller is loaded, the HTTP request and any user submitted data is filtered for security.
The Controller loads the model, core libraries, helpers, and any other resources
needed to process the specific request.
The finalized View is rendered then sent to the web browser to be seen. If caching is enabled, the view is cached first so that on subsequent requests it can be served.
Q:- Explain MVC in Codeigniter.?
CodeIgniter is based on the Model-View-Controller development pattern. MVC is a software approach that separates application logic from presentation.
The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert, and update information in your database.
The View is the information that is being presented to a
user. A View will normally be a web page, but in CodeIgniter, a view can also be a page fragment like a header or footer. It can also be an RSS page, or any other type of "page".
The Controller serves as an intermediary between the Model, the View, and any other resources needed to process the HTTP request and generate a web page.
You may also like - CakePHP Interview Questions
CodeIgniter | CodeIgniter Interview Questions | Advanced
Q:- What are the hooks in codeigniter?
CodeIgniter’s Hooks feature provides a means to tap into and modify the inner workings of the framework without hacking the core files.How ever you like to
cause some action to take place at a particular stage in the execution process.
The hooks feature can be globally enabled/disabled by setting the following item in the application/config/config.php file:
codesource
$config[‘enable_hooks’] = TRUE;
Hooks are defined in application/config/hooks.php file.
For example
codesource
$hook['pre_controller'] = array(
'class' => 'MyClass',
'function' => 'Myfunction',
'filename' => 'Myclass.php',
'filepath' => 'hooks',
'params' => array('param1', 'param2', 'param3')
);
Q:- What are the different types of
hook in Codeigniter?
post_controller_constructor
pre_controller
pre_sytem
post_sytem
cache_override
display_override
post_controller
You may also like - Top 50 Laravel Interview Questions
Q:- What are the helpers in codeigniter?
Helpers, as the name suggests, help you with tasks. Each helper file is simply a collection of functions in a particular category.
There are many inbuilt helpers few of them are:
URL Helpers
Form Helpers
Text Helpers
Cookie Helpers
File Helpers
CodeIgniter does not load Helper Files by default, so the first step in using a Helper is to load it. Once
loaded, it becomes globally available in your controller and views.
Helpers are typically stored in your system/helpers, or application/helpers directory.
CodeIgniter will look first in your application/helpers directory. If the directory does not exist or the specified helper is not located there CI will instead look in your global system/helpers folder.
Loading a Helper
Loading a helper file is quite simple using the following function:
codesource
$this->load->helper('helper_name');
Where helper_name is the file name of the helper, without the .php file extension or
the "helper" part.
For example, to load the URL Helper file, which is named url_helper.php, you would do this:
codesource
$this->load->helper('url');
A helper can be loaded anywhere within your controller functions (or even within your View files, although that's not a good practice), as long as you load it before you use it.
You can load your helpers in your controller constructor so that they become available automatically in any function, or you can load a helper in a specific function that needs it.
Note: The Helper loading function above does not return a value, so don't try to assign it to a
variable. Just use it as shown.
Loading Multiple Helpers
If you need to load more than one helper you can specify them in an array, like this:
codesource
$this->load->helper( array('helper1', 'helper2', 'helper3') );
Auto-loading Helpers
If you find that you need a particular helper globally throughout your application, you can tell CodeIgniter to auto-load it during system initialization. This is done by opening the application/config/autoload.php file and adding the helper to the autoload array.
Using a Helper
Once you've loaded the Helper File containing the function you intend to use, you'll call it the way you would a
standard PHP function.
For example, to create a link using the anchor() function in one of your view files you would do this:
codesource
echo anchor('blog/comments', 'Click Here');
Where "Click Here" is the name of the link, and "blog/comments" is the URI to the controller/function you wish to link to.
"Extending" Helpers
To "extend" Helpers, create a file in your application/helpers/ folder with an identical name to the existing Helper, but prefixed with MY_ (this item is configurable. See below.).
For example, to extend the native Array Helper you'll create a file named application/helpers/MY_array_helper.php,
and add or override functions:
codesource
// any_in_array() is not in the Array Helper, so it defines a new function
function any_in_array($needle, $haystack)
{
$needle = (is_array($needle)) ? $needle : array($needle);
foreach ($needle as $item)
{
if (in_array($item, $haystack))
{
return TRUE;
}
}
return FALSE;
}
codesource
// random_element() is included in Array Helper, so it overrides the native function
function random_element($array)
{
shuffle($array);
return array_pop($array);
}
Setting Your Own
Prefix
The filename prefix for "extending" Helpers is the same used to extend libraries and Core classes.
To set your own prefix, open your application/config/config.php file and look for this item:
$config['subclass_prefix'] = 'MY_';
Please note that all native CodeIgniter libraries are prefixed with CI_ so DO NOT use that as your prefix.
Q:- How you will use or add codeigniter libraries?
All of the available libraries are located in your system/libraries folder.
In most cases, to use one of these classes involves initializing it within a controller using the following initialization
function:
codesource
$this->load->library('classname');
Where class name is the name of the class you want to invoke.
For example, to load the form validation class you would do this:
codesource
$this->load->library('form_validation');
Once initialized you can use it as indicated in the user guide page corresponding to that class.
Additionally, multiple libraries can be loaded at the same time by passing an array of libraries to the load function.
codesource
$this->load->library(array('emailtable'));
Q:- How you will work with error handling in
codeigniter?
CodeIgniter lets you build error reporting into your applications using the functions:-
1. show_error()
This function will display the error message supplied to it using template application/errors/error_general.php.
2. show_404()
Function will display the 404 error message.
3. log_message("level", "message")
This function lets you write messages to your log files.
You must supply one of three "levels" in the 1st parameter, indicating what type of message it is (debug, error, info), with the log message itself in the 2nd parameter.
debug
error
info
Q:- Explain what is inhibitor in
CodeIgniter?
In CodeIgniter, inhibitor is an error handler class, using the native PHP functions like
set_exception_handler
set_error_handler
register_shutdown_function
register_shutdown_function
to handle parse errors, exceptions, and fatal errors.
Q:- Explain routing in Codeigniter?
In CodeIgniter, the way PHP files served is different rather than accessing it directly from the browser. This process is called routing.
Routing in CodeIgniter gives you the freedom to customize the default URL pattern to use our own URL pattern according to the requirement.
So, whenever there is a request made and matches
our URL pattern it will automatically direct to the specified controller and function.
Open the routing file located at application/config/routes.php and add the following two lines.
codesource
$route['default_controller'] = "welcome"; // default controller name
$route['404_override'] = ''; // 404 page
Q:- Why there is a need to configure the URL routes?
Changing the URL routes has some benefits like
SEO-friendly URLs: From SEO point of view, to make URL SEO friendly and get more user visits Hide some URL element such as a function name, controller name, etc.
Security: from the users for security reasons Provide
different functionality to particular parts of a system.
Q:- How to set & unset session variable in codeigniter?
Set Single Value:
codesource
$this->session->set_userdata('SESSION_NAME', 'CodeIgniter Interview Questions and Answers');
Set Multiple Value:
codesource
$newdata = array(
'username' => 'FullStackTutorials',
'email' => 'fullstacktutorials@gmail.com',
'logged_in' => TRUE
);
$this->session->set_userdata($newdata);
Verify session value:
If you want to verify that a session value exists, simply check with
has_userdata()
codesource
$this->session->has_userdata('SESSION_NAME');
Unset Session:
codesource
$this->session->unset_userdata('SESSION_NAME');
unset multiple thing at in single call
$array_items = array('username', 'email');
$this->session->unset_userdata($array_items);
Flashdata:
CodeIgniter supports "flashdata", or session data that will only be available for the next request, and is then automatically cleared.
This can be very useful, especially for one-time informational, error or status messages (for example: "N Record
deleted").
To add flashdata:
codesource
$this->session->set_flashdata('item', 'value');
However, if you want to be sure that you’re reading "flashdata" (and not any other kind), you can also use the flashdata() method:
codesource
$this->session->flashdata('item');
Or to get an array with all flashdata, simply omit the key parameter:
$this->session->flashdata();
To mark an existing item as "flashdata":
codesource
$this->session->mark_as_flash('item');
If you want to mark multiple items as flashdata, simply pass the keys as an
array:
codesource
$this->session->mark_as_flash(array('item', 'item2'));
Preserve flashdata:
If you find that you need to preserve a flashdata variable through an additional request, you can do so using the keep_flashdata() method. You can either pass a single item or an array of flashdata items to keep.
codesource
$this->session->keep_flashdata('item');
$this->session->keep_flashdata(array('item1', 'item2', 'item3'));
Tempdata:
CodeIgniter also supports "tempdata", or session data with a specific expiration time. After the value expires, or the session expires or is deleted, the value is
automatically removed.
To mark an existing item as "tempdata", simply pass its key and expiry time (in seconds!) to the mark_as_temp() method:
codesource
// 'item' will be erased after 300 seconds
$this->session->mark_as_temp('item', 300);
You can mark multiple items as tempdata in two ways, depending on whether you want them all to have the same expiry time or not:
// Both 'item' and 'item2' will expire after 300 seconds
$this->session->mark_as_temp(array('item', 'item2'), 300);
// 'item' will be erased after 300 seconds, while 'item2'
// will do so after only
240 seconds
$this->session->mark_as_temp(array(
'item' => 300,
'item2' => 240
));
To add tempdata:
codesource
$_SESSION['item'] = 'value';
$this->session->mark_as_temp('item', 300); // Expire in 5 minutes
Or alternatively, using the set_tempdata() method:
$this->session->set_tempdata('item', 'value', 300);
You can also pass an array to set_tempdata():
$tempdata = array('newuser' => TRUE, 'message' => 'Thanks for joining!');
$this->session->set_tempdata($tempdata, NULL, $expire);
Note:
If the
expiration is omitted or set to 0, the default time-to-live value of 300 seconds (or 5 minutes) will be used.
The userdata() method will NOT return flashdata items.
The userdata() method will NOT return tempdata items.
Destroying a Session:
To clear the current session (for example, during a logout), you may simply use either PHP’s session_destroy() function, or the sess_destroy() method. Both will work in exactly the same way:
codesource
session_destroy();
OR
$this->session->sess_destroy();
Q:- Mention what is the default URL pattern used in Codeigniter framework?
Codeigniter
framework URL has four main components in default URL pattern.
First we have the server name and next, we have the controller class name followed by controller function name and function parameters at the end.
codesource
#Example:http://serverName/controllerName/controllerFunction/parameter1/parameter2.
GET URI SEGMENT IN CODEIGNITER:
$this->uri->segment(1); // controller name
$this->uri->segment(2); // action name
$this->uri->segment(3); // 1st segment
$this->uri->segment(4); // 2nd segment
Q:- Question: How to access config variable in codeigniter?
codesource
$this->config->item('VARIABLE_NAME');
Q:- Explain how you can enable CSRF (Cross Site Request Forgery) in CodeIgniter?
Go to the path - application/config/config.php
codesource
$config['csrf_protection'] = TRUE;
The CSRF token is added to the form as a hidden input only when the form_open() function is used.
A cookie with the CSRF token's value is created by the Security class, and regenerated if necessary for each request.
If $_POST data exists, the cookie is automatically validated by the Input
class. If the posted token does not match the cookie's value, CI will show an error and fail to process the $_POST data.
So basically, it's all automatic - all you have to do is enable it in your $config['csrf_protection'] and use the form_open() function for your form.
CodeIgniter | CodeIgniter Interview Questions | Database
You may also like - MySQL Interview Questions
Q:- What is Model in CodeIgniter?
Model’s responsibility is to handle all data logic and representation and load data in the views. It is stored in application/models folder.
Q:- How to load a model in CodeIgniter?
Your models will typically be loaded
and called from within your controller methods. To load a model you will use the following method:
codesource
$this->load->model('model_name');
If your model is located in a sub-directory, include the relative path from your models directory.
For example, if you have a model located at application/models/blog/Queries.php you'll load it using:
codesource
$this->load->model('blog/queries');
Once loaded, you will access your model methods using an object with the same name as your class:
codesource
$this->load->model('model_name');
$this->model_name->method();
If you would like your model
assigned to a different object name you can specify it via the second parameter of the loading method:
codesource
$this->load->model('model_name', 'foobar');
$this->foobar->method();
Q:- How do you get last inserted ID in Codeigniter?
codesource
$this->db->insert_id();
Q:- How to print SQL statement in codeigniter model?
codesource
$this->db->last_query();
Q:- How to load helpers in CodeIgniter?
codesource
$this->load->helper('helperName');
Q:- How can you connect models to a database manually?
codesource
$this->load->database();
SOURCE:
https://www.fullstacktutorials.com/interviews/codeigniter-interview-questions-and-answers-3.html