75+ CodeIgniter Interview Questions To Hire Or Get Hired With

CodeIgniter is a popular PHP framework for developers. It is a popular tool in the polyglot toolkit. CodeIgniter is a wonderful framework for those looking to work with PHP, which is a very stable and scalable language type. Those who are debating more modern languages often pick PHP because of its ability to grow with the functionality needs of web applications very easily. Below are some CodeIgniter interview questions and answers to get you started in preparing for your next job interview or to perform a technical job interview. As with all of the questions, I highly recommend that you sit with a friend and go through a mock interview session to get you more ideally prepared.

1. Describe CodeIgniter.

• This is an open source framework that developers use for website building on PHP.
• It is primarily utilized in building web applications and websites.
• It is based on MVC pattern and has features almost similar to those of CakePHP.
• It has a fast speed.
• One of the advantages of using this software is that the developer will have access to a huge set of libraries, logical structures and a simple interface and this will facilitate in creating projects more swiftly and with ease.

2. List the major features of code igniter.

• It is an open source framework and free to use.
• It is light weight.
• It is based one MVC pattern.
• It offers full featured database classes and will support various platforms.
• It can be easily expanded or extended by using the developers’ libraries and helpers.
• Has excellent documentation capabilities.

3. When was CodeIgniters initial release and what it is the current version?

• It was initially released in February 2006. The software has been greatly updated for instance there is version 3.0 dev was released in fall of 2011.
• The 2.2.0 version was released in 204 and the current version (2.2.6 was released in October 2015.

4. Describe what hooks are in CodeIgniter.

• They are unique features that used to alter the performance and functionality of PHP framework.
• Hooks are useful because thy allow developers to modify scripts using specific paths in the CodeIgniter execution process. Therefore developers will not need to write the scripts over and over again.

5. List the various types of hooks in CodeIgniter.

• Display _Override • Post_controller_constructor
• Pre_controller
• Post_system
• Pre_system
• Cache_override
• Post_controller

6. What is the CodeIgniter architecture?

• Technically, CodeIgniter is a software that is dynamically instantiation because it is light weighted, it is loosely coupled its components rarely depend on each other and it has component singularity due to the fact that each class and functions are narrowly focused towards their purpose.

7. Describe how you would add or load a model in CodeIgniter?

• I would do load models using the function: $this->load->model (‘ModelName’);

8. Explain how you can connect models to database manually?

• I would connect to the database manually using the following function: • $this -> load -> databse();

9. Explain the CodeIgniter file structures?

• When you download the software you will find a folder structure with application – helpers, hooks, language, library, cache models, views, third party and controllers.
• The system core on the other had has databases, fonts language and libraries.

10. Explain views in CodeIgniter?

• Inside the views folder you will find all the markup files like headers, footers and sidebars.
• They are used by integrating the in any section of the controller file.
• They lack the capability of working on their own and therefore, they are loaded in the controller file.

11. Give the basic CodeIgniter URL structure

The software uses segment based approach with the following structure abc.com/class/function/ID The class in this function is the controller class being worked on, the function indicates the method that is called while the ID is the additional segment that is moved to the controllers.

12. Mention the default method name in CodeIgniter?

• The default controller calls the index method.
• In case the developer intends to call a different method, he or she will have to write it in the controller file and specify its name while calling the function.

13. Describe the remapping method calls as they are used in CodeIgniter?

• This used to determine which method is being called. • When overriding the developer will utilize _remap() method.
• Remapping can be applied even if the URl is different because it overrides the URI.

14. Describe Helper in CodeIgniter.

• They are set of functions that help developers to perform specific functions.

15. Give examples of helpers.

• URL helpers- used in creating links.
• Text helpers- perform text formatting routines.
• Cookies helpers Set and read cookies.

16. Give a function for loading helper file.

• $this - > load -> model (‘ModelName’);

17. What is a CodeIgniter library and how can you load it?

• It is used to give developers access to a set of libraries and this improves the development speed.
• It is situated in the system/library
• The function of loading library is $this -> load -> library (class_name’);

18. List the main methods used to create a library in CodeIgniter?

• Building a whole new library.
• Extending the native libraries.
• And replacing native libraries.

19. Give an example of a stable version of CodeIgniter?

• Version 3.0.5 released January 13, 2016.

20. Give the default URl pattern used in CodeIgniter?

• Typically there are four main components in CodeIgniter. they occur as server name, controller call , controller function name and lastly the function parameters.
• Syntax: http://serverName/controllerName/controleerFunction/Parameter1/parameter2.

21. Explain MVC in CodeIgniter?

• This is an abbreviation of Model View Control. It is the pattern that separates the application logic from presentation. Through it developers can benefit from minimal scripting.

22. Explain how you can set default time zone in CodeIgniter.

This can be done by adding date_default_timezone_set(‘Your timezone’); in the Index.PHP

23. Mention the language used to write CodeIgniter.


24. give the syntax for accessing Config Variable in CodeIgniter?

• $this->config->item(Variable name’)

25. Describe how you can unset a session in CodeIgniter?

This can be done using the syntax; $this->session->unsetuserdata(‘somename’);

26. Describe the application flow chart in CodeIgniter?

• Index.PHP is utilized as a font controller and is useful in activating the base resources used to run CodeIgniter.
• The router checks the HTTP request.
• The cache files are used to bypass normal system execution.
• Security is used for filtering data prior to loading of application controller ad requesting the HTTP.
• The controller is a tool that is used to load models, libraries, helpers and any other resources need to initialize some specific requests.
• The finalize view is later rendered and presented on the web browser. When caching is enabled the view is cached first so that on subsequent requests it can be served.

27. Explain how you can Extend Native libraries in CodeIgniter.

• This can be done by adding some extended functionality to a native library by adding on or two methods.

28. Describe bow a class can be extended in CodeIgniter.

• I would do this by developing a file a name Application/core/MY_input and declare class with Class MY_Iput extends CI _ Input {} to extend the native input class in CodeIgniter.

29. Describe how you can achieve Error handling in CodeIgniter.

• It is possible to build error reporting in the application using various functions.
• The software also has error logging class that permits error and debugging messages to be saved as text files.
• Examples of functions used for this purpose include;

Show_error(‘massage’ [, Int $statuscode=500] )
Log_message(‘level’, ‘message’) this specific code is used to write messages to the log files.

30. How is autoloading achieved by the use of aliases in CodeIgniter?

• Syntax; $autoload[‘model’] =array (array(usersmodel’, ‘users’), array(newsmodel’,news’), ‘categorymodel’)

31. How do you access Random recording in MySQL using CodeIgniter?

• Syntax; $this->db->order_by(‘id’, ‘RANDOM’);

32. Explain the security parameter for XSS.

• CodeIgniter is unique in that it has cross-site scripting hack prevention filter which runs either automatically or per items in use and is useful in filtering all Post and Cookie data in the software.
• The XSS filter targets the popular methods used to initiate Javascript and other methods used to hijack cookies among other malicious activity.
• Upon noticing suspicious activities it will disallow it an convert the data into character entities.

33. Who is the developer behind CodeIgniter?

• Ellislab Inc and is currently a project of the British of Columbia institute of technology.

34. Why is the software considered a loosely based MVC framework?

This is because developers does not need to follow strict MVC pattern while creating application. It is also possible to build with model only view and controllers are sufficient to develop applications.

35. Explain the different types of messages that a user can log.

• Error messages- these are actual errors such as User errors and PHP errors.
• Debug messages - they assist in debugging.
• Informational messages- they are low priority messages that give information related ot particular processes.

36. Explain the directory the logs are saved in CodeIgniter.

In logs/directory , all logs are stored by default. In order to achieve error logging the developer will need to set the “threshold” for logging in application/cofig.PHP and logs need to be writable.

37. In which routes are files defined in CodeIgniter?

• All routing rules in CodeIgniter is are defined in Applicaion/config/routes.PHP file.

38. List the resources that can be autoloaded in CodeIgniter.

• In Libraries/ directory, classes are not available.
• In helpers/ directory the helper files are unavailable.
• In system language/ directory, language files are not available.
• In config/directory, custom config file s are found.
• In models/ folder, models are found.
• The syntax for loading is application /config/autoload.PHP file an then add the item you want to load to the autoload array

39. What is ORM?

ORM is the abbreviation for Object relational mapping. It is the method used for reorganizing data between incompatible type systems using object oriented programming languages.

40. What type of ORM can you find in CodeIgniter?

The list below shows ORM’s supported by CodeIgniter:

• Data mapper
• Doctrine
• Gas ORM

41. Describe how you can delete a record in CodeIgniter.

• The delete function is used for this purpose in CodeIgniter.
• Syntax; [SyntaxHL]Example:DELETE FROM Table WHERE id=$id

$condiotions =[‘id=>$id]
$this=>db=>delete(‘table_name’, conditions);
• You can also delete record form more than one table using the syntax below
$tables = Array (‘table1’, ‘table2’, ‘table3’);
$this ->db => where (‘id’, $id);
$this -> db ->delete ($tables); [/SyntaxHL]

42. Describe how you can use and load libraries in CodeIgniter.

The basic process of loading library in code igniter is $this->load->library(library_name’):
The syntax for load cart library occurs as:
$this -> load ->library (‘cart’)
$data = array (
‘Id’ => ‘Sku_9788B’,
‘qty’ => 36.92,
Name => ‘T-shirt’
‘options’ => array (‘size’ => ‘XL’, => ‘Blue’)
$this -> cart -> inside ($data); [SyntaxHL]

43. How would you use IS_cli()Mehtod in CodeIgniter?

• I would use the method to check if a request comes from command line or not.
• By running the application through command line, it indicates True if I comes for the command line and will indicate false, if not.

44. Explain how you can fetch the as inserted ID.

Insert_id function is used for this purpose
The syntax for fetching the last inserted id is:
Function add_post($post_data){
$this->db->insert(‘posts’, $post_data);
$insert_id = $this->db->insert_id();
return $insert_id; }[/SyntaxHL]

45. Define what sessions are and how can you create and read session.

• They are used to maintain a users “state” and track their activities during their browsing on your website.
• They can be created by lading session class to the controller.
• The loading can be done by using $this->load->library(‘Session’) function.
• The method to access the session library is $this->session.
• Session can be created using the methods.
• The set_userdata() method is used for this purpose while the Class.set_userddata() method is used to indicate the array that holds the data that will be added to the session.
• Syntax example;
$newdata = array(
‘username’ => ‘ruchi’,
’email’ => ‘[email protected]’,
‘logged_in’ => TRUE
Process and method of reading a session;
• $this->session->userdata() method is used to read data in session class
• A syntax example for this purpose is $this->session->userdata(‘your_key’);[/SyntaxHL]

46. Describe the process of loading a model.

The function used for this purpose is $this->load->model(‘model_name’);
After initiating the method, the developer will have access the methods using an object with the same name as the controller.
class Blog_controller extends CI_Controller {
public function blog()
$data[‘query’] = $this->blog->get_last_ten_entries();
$this->load->view(‘blog’, $data);

47. List the features of sending an email in CodeIgniter.

• Sending emails in CodeIgniter is never a sophisticated process.
• Here are the features that are used for sending email:
• 1. Multiple recipients
• 2. HTML or Plaintext email
• 3. Word wrapping
• 4. Attachments
• 5. BCC Batch Mode
• 6. Email Debugging tools
• 7. Multiple Protocols − Mail, Sendmail, and SMTP
• 8. TLS and SSL Encryption for SMTP
• 9. CC and BCCs
• 10. Priorities

48. In CodeIgniter, what is the process of sending an email?

• The basic method of sending an email is using $this->load->library(’email’); code. This is used to load the email library then the syntax below are used for sending the emails.
• form()->used to indicate the location from where the email is being sent.
Example:$this->email->from(‘[email protected]’, ‘Your Name’);
• to()->It is used to show the recipients of the email.
Example:$this->email->to(‘[email protected]’);
• subject()->It is used to set the subject of the email.
Example:$this->email->subject(‘Email Test’);
• message()->It is used to set the message of the email.
Example:$this->email->message(‘Testing the email class.’);
• send()->It is used to execute to send an email.

49. Define flash data and the process of adding and retrieving it.

This occurs after the application has been build and the developer needs to store some data and then remove it. ‘probably this could be done to display the error message:
[SyntaxHL]// Set flash data
$this->session->set_flashdata(‘message_name’, ‘This is my message’);
// Get Flash data on view

50. Describe inhibitors as they occur in CodeIgniter.

• An inhibitor is an error handler class in CodeIgniter.
• Through it developers can handle parse errors, exceptions, fatal errors while using native PHP functions like et_exception_handler, set_error_handler, register_shutdown_function tech.

51. How can you load multiple helpers in CodeIgniter?

This can be done by specifying the in array
The methods used for this purpose is;
array('helper1', 'helper2', 'helper3')

52. Where can a developer store the newly created library in the CodeIgniter structure?

They can be stored in application/libraries folder

53. How can you extend the native libraries in CodeIgniter?

• Using the class declaration to extend the parent class. • Prefixing the new calls name and file name using the MY_ function.

53. what is the process of extend a class in CodeIgniter?

This can be done by developing a file name application/core/MY_Input.PHP then the developer will need to declare the class using the function Class MY_Input extends CI_Input {} and this will extend the native input in CodeIgniter.

54. Explain the major ways of routing in CodeIgniter.

Routing in CodeIgniter is done using wildcards or expression.

Wildcards can be classified as: • :Num-series they contain only numbers matched
• :any-series the contain only characters matched
Regular expression: they are used to redirect routes

An example of syntax used for this purpose is;
$route['blog'(a-zA-Z0-9]+)'] = 'women/social';
It is also possible to create a regular expression to run the URL.

55. Why do developers need the URL routes configured?

Mainly developer’s configure the URL routes in order to;

• Improve the number of page visits
• Hide the code complexities for the user

56. Give the function for enabling hooks in CodeIgniter.

• This can be done by enabling hook through Application/config/config.PHP and setting it to true. The syntax for this process is $config['enable_hooks'] = TRUE;

57. Describe the different types of hook points as they occur in CodeIgniter.

• Post _controller constructor; this is called immediately after the controller has been started and prior to making any method call.
• Pre_controller; this hook is called immediately before your controller is called. Here, all the calluses security checks and routing has been achieved.
• Post_system; this is called after the final page is sent to the browser at the end of the system execution.
• Pre_system; this hook is called prior to system execution. This is done when only the benchmark and hook class has been loaded.
• Cache_overide; it enables the developer to call the function in the output class.
• Display _ override; this used to send the final page at the end of the file execution.
• Post controller; this hook point s called immediately after the controller is entirely executed.

58. Describe the CodeIgniter drivers.

They are type of library that has parent class and multiple child classes.
The child classes can access the parent class but not to their siblings.
The drivers can be accessed via system/libraries folder

59. Explain how you would initialize a driver in CodeIgniter?

• The syntax used for this purpose is as follows: $this->load->driver('class_name');

60. List the steps of creating a driver in CodeIgniter.

• Making file structure
• Making driver list
• Making driver(s)

61. What is the process of printing SQL statement in CodeIgniter model?

• $this>db>insertid();

62. List the CodeIgniter security methods?

• XSS filtering
• CSRF (Cross-site Request forgery)
• Class reference

63. Describe how CodeIgniter can be prevented from CSRF.

Various methods exist for this purpose, but the most popular one is using the hidden filed in each page of the website. The hidden field is stored in user’s session. The file is changed upon every HTTP request.

The user can be detected in its every request to the website.

The developer will need to compare hidden values with the ones saved in the session if the two are similar the request is valid.

64. Give the syntax you would use to enable the CSRF?

• This can be done by editing the Config.PHP file and setting it to true in the application/config/config.PHP file
• The syntax for this process is $config['csrf_protection'] = TRUE;

65. Describe a CSRF attack in CodeIgniter?

This an attack that compels a logged-on victims browser to send a forged HTTP request, such as the victims session cookies and other authentication information to a web application.

During such an attack the victim risk having folders and files with hidden inputs and malicious data sent to their websites. The site will process such data ad this might make the attacker gain the ability to delete the users account without the victim detecting it.

66. Describe the token method in a CSRF attack?

• The method used to prevent a CSRF attack is connecting the HTTP request and form submission.
• In CodeIgniter, the hidden field is used and this is called the CSRF token.
• The token is a random value that changes with every HTTP request.
• Upon request a new CSRF token is generated and this creates an object, name and value of the token.

Here is an example syntax:
$this->csrf_cookie_name = $this->csrf_token_name;

A function for the process is
function _csrf_set_hash()
if ($this->csrf_hash == '')
if ( isset($_COOKIE[$this->csrf_cookie_name] ) AND
$_COOKIE[$this->csrf_cookie_name] != '' )
$this->csrf_hash = $_COOKIE[$this->csrf_cookie_name];
} else {
$this->csrf_hash = md5(uniqid(rand(), TRUE));
return $this->csrf_hash;

67. Describe the data mapper in CodeIgniter.

This is a tool that is used to map the database tables into an easy to work with objects. These databases has the capability to understand the relationships between each other.

68. What is Gas ORM?

• This a light weight easy to use ORM.
• It was developed for CodeIgniter app.
• The ORM uses CodeIgniter data packages that supports DB drivers.
• The ORM offers a set of methods that help in mapping the database tables and its relationship into accessible object.

69. Explain the difference between Helper and library in CodeIgniter?

Helpers are functions that help developers to avoid repetitive code and produce standard results while the libraries come with classes and include files, talk to databases.

70. Explain the difference between helpers, plugin, and library?

Plugins are used to access 3rd party and using classes rather than making direct function calls. Helpers are used to make standalone direct function calls ad libraries are they are used to write cases in the application.

71. Give the syntaxes for setting and unsetting session variables in CodeIgniter?

Set single value:
$this->session->set_userdata('SESSION_NAME', 'CodeIgniter Interview Questions and Answers');
Set multiple values:
$newdata = array(
'username' => 'FullStackTutorials',
'email' => '[email protected]', 'logged_in' => TRUE);
If you want to verify that a session value exists, simply check with isset():

Unset session:
unset multiple thing at in single call
$array_items = array('username', 'email');

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: “Record 2 deleted”).

To mark an existing item as “flashdata”:
If you want to mark multiple items as flashdata, simply pass the keys as an array:
$this->session->mark_as_flash(array('item', 'item2'));

To add flashdata:
$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: $this->session->flashdata('item');
Or to get an array with all flashdata, simply omit the key parameter:
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.
$this->session->keep_flashdata(array('item1', 'item2', 'item3'));

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:
// '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
'item' => 300,
'item2' => 240

To add tempdata:
$_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);

• 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:



72. Explain how you can connect model to a database manually?


73. Name the different types of hook point in CodeIgniter?

There are several types of hook points in CodeIgniter namely;

73. In CodeIgniter, how do you link images/CSS/JavaScript from a view?

HTML is a PHP server-side framework which means that there is no Codeingiter way of linking. You simply take the absolute path to your resource in order to link images/CSS/JavaScript from a view in CodeIgniter

74. How can you prevent CodeIgniter from CSRF?

There are several ways of preventing CodeIgniter from CSRF. One of the ways is by using a hidden field in each of the form on the website creating a hidden field referred to as CSRF token. This field is a random value that changes with each HTTP request. As soon as a CSRF token is entered into the website forms, it is saved in the user’s session as well. When the user submits the forms again, the website checks to see if the token is similar to the one saved during the previous session. If the value is the same, then the request is considered legitimate.

75. How is CSRF (Cross Site Request Forgery) enabled in CodeIgniter?

By operating the application/config/config.PHP file and setting it to: $config [ ‘csrf_protection’] = TRUE;

76. Why are URL routes configured in CodeIgniter?

URL configuration is essential for the following reasons; • Makes the URL SEO friendly hence increasing the number of user visits.
• Hides some elements of the URL such as controller name and function name from the users for security reasons.
• Provides several functionalities to specific parts of a system.

77. What is the process of extending a class in CodeIgniter?

This can be done by developing a file name application/core/MY_Input.PHP then the developer will need to declare the class using the function Class MY_Input extends CI_Input {} and this will extend the native input in CodeIgniter.

author: patrick algrim
About the author

Patrick Algrim is an experienced executive who has spent a number of years in Silicon Valley hiring and coaching some of the world’s most valuable technology teams. Patrick has been a source for Human Resources and career related insights for Forbes, Glassdoor, Entrepreneur, Recruiter.com, SparkHire, and many more.


Help us by spreading the word