CodeIgniter Interview Questions and Answers [ TO GET HIRED ]

CodeIgniter Interview Questions and Answers [ TO GET HIRED ]

Last updated on 18th Nov 2021, Blog, Interview Questions

About author

Kanagavel (PHP Developer - Codeigniter )

Kanagavel is a PHP Developer Expert with 7+ years of experience in PHP, JavaScript, CSS-Cascading Style Sheets, MySQL, Core PHP, and Bootstrap. He spends most of his time researching technology and startups.

(5.0) | 19587 Ratings 3355

    If you are an aspiring PHP Developer and have interviews lined up, go through these Codeigniter interview questions and answers that are frequently asked by interviewers of top companies. The following list of interview questions on Codeigniter covers the conceptual questions for freshers and experts and helps you answer different questions like directory structure of Codeigniter, the architecture of Codeigniter, MVC in Codeigniter, different libraries in Codeigniter, etc. Master the top Codeigniter interview questions and answers and crack your next PHP Developer, Backend Developer CodeIgniter interviews, and many more.

Subscribe For Free Demo

1.What is CodeIgniter?


    CodeIgniter is an open-source and MVC-based framework used for web application development on PHP. This framework contains libraries, an easier interface with a logical structure to access these libraries, helpers, plug-ins, and other resources as well. It is easy to use compared to other PHP frameworks.

2.What are hooks in CodeIgnitor?


  • CodeIgniter’s hooks will provide a way to change the internal workings or framework functionalities without any need for hacking the core files. It permits script execution with a particular path within the CodeIgniter.
  • We can globally enable/disable the hooks feature by setting the below-given item in the application/config/config.php file: $config[‘enable_hooks’] = TRUE;
  • It is defined in application/config/hooks.php file.

3.What is an inhibitor in CodeIgniter?


    An inhibitor in CodeIgniter is an error handler class. It will make use of PHP’s native functions like set_error_handler, set_exception_handler, register_shutdown_function to handle parse errors, exceptions, and fatal errors.

4.How to check the CodeIgniter version?


    There are 2 ways to check the CodeIgniter version:-

  • The first method is to run the following code:
  • You can echo the constant value of CI_VERSION in the CodeIgniter controller or view file.
  • The second method is to navigate to the system/core/CodeIgniter.php directory which stores the current version number of CodeIgniter in a global constant named ‘CI_VERSION’. Open the file and have a look at the lines:

5.Explain the difference between helper and library in CodeIgniter.


Helper is a collection of common functions which we can use within Models, Views as well as in Controllers. Once we include the helper file, we can get access to the functions. Library is a class that has a set of functions that permits for creating an instance of that class by $this->load->library() function.
It is not written in object-oriented format. It is written in an object-oriented format.
It can be called in the same manner you call PHP functions. You must create an object of the class to call library functions by using the $this->library_name->method().
All built-in helper file names are suffixed with a word _helper (ex: email_helper.php). All built-in library files do not have a specific suffix.

6.What is REST API in Codeigniter?


    A REST API is a web service which uses HTTP methods likes GET, PUT, POST, DELETE for data manipulation over the cross platforms. In this tutorial, I will demonstrate How you can create a REST API in Codeigniter.

7.What are drivers in CodeIgniter?


  • A driver is a type of library that has a parent class and multiple child classes. These child classes can access their parent class, but they can’t access their siblings.
  • Drivers can be found in the system/libraries folder.
  • There are three steps for creating a driver:
  • Making file structure
  • Making driver list
  • Making driver(s)

8.How to link images from a view in CodeIgniter?


    In Codeigniter, you can link images/CSS/JavaScript from a view by using the absolute path to the resources required with respect to the root folder as given below:-

  • /css/styles.css
  • /js/query.php
  • /img/news/566.gpg

9.Why CodeIgniter is called a loosely based MVC framework?


    Codeigniter is called a loosely based MVC framework because it does not need to obey a strict MVC pattern during application creation. It is not important to create a model, we can use only view and controllers for creating an application. In addition, one can modify CodeIgniter to utilize HMVC(Hierarchical Model View Controller) as well.

10.What is a helper in CodeIgniter?


  • Helpers are the group of functions that are useful in assisting the user to perform specific tasks.
  • There are three types of helper files. They are:
  • URL helpers: Used for creating the links.
  • Text helpers: Used for the formatting of text.
  • Cookies helpers: Used to read and manage cookies.

11.Explain CodeIgniter Architecture.


  • CodeIgniter is mainly designed to deliver high performance in less time within a good environment. For achieving this, each developing process is designed in a simplified manner.
  • From the technical point of view, it is dynamically instantiated (libraries are loaded only on request which makes it light-weighted), has loose coupling (components depend very less on each other), and component singularity (each class and its functions are focused only on their purpose).
  • Data flow in CodeIgniter: Below image represents that whenever a request is raised from the CodeIgniter application, firstly, it will go to the index.php file.
  • index.php is the default file of CodeIgniter. This file initializes the base resources.
  • The router determines what should be done with the information.
  • If the requested cache file exists, then the information is moved directly to the browser and ignores the further processes.
  • If the page requested by the user does not exist in the caching file, the HTTP request and data submitted will be passed under security check.
  • The application controller will load the models, libraries, helpers, plugins, and scripts required according to the request.
  • A view is used for fetching the data from the application controller that will be represented to the user, and they pass the data to the caching file to the fastest access for future requests.

12.How to load a helper in CodeIgniter?


  • You need to load the helper files for using it. Once loaded, it will be globally available to your controller and views. They can be obtained at two places in CodeIgniter. A helper file will be searched by CodeIgniter in the application/helpers folder and if it is not available in that folder then it will check in the system/helpers folder.
  • Helper file can be loaded by adding the following code to the constructor of the controller or inside any function that wants to use: $this->load->helper(‘file_name’); Write your file name at the place of file_name.
  • To load URL helper we can use the code given below: $this->load->helper(‘url’);
  • You are allowed to auto-load a helper if your application needs that helper globally by including it in the application/config/autoload.php file.

13.What are the advantages of CodeIgniter?


    Few advantages of using CodeIgniter is given below:-

  • Built-in libraries: It comes with various types of default helpers for multiple things including strings, arrays, cookies, directories, file handling, and forms among others.
  • Data abstraction: You can make use of the CodeIgniter database abstraction layer for creating, adding, deleting, and replacing statements in a hassle-free manner. This framework allows you to manage multiple connections using a single application.
  • Active Developer Community: Bigger the community, the better the help you get. Newly graduated developers look forward to the framework’s forum to get their doubts solved and learn about new things in the process. With so many people actively participating in it from around the world, your doubts will be solved within few hours. And due to the same reason, CodeIgniter documentation is 10 times bigger than any other framework.

14.Give the list of hooks available in CodeIgniter.


    The list of available hook points are given below:-

  • pre_system: It is called initially during system execution.
  • pre_controller: It is called immediately before any of the controllers being called.
  • post_controller_constructor: It is called soon after instantiating your controller, but before any occurrence of the method call. post_controller: It is called immediately after the complete execution of the controller.
  • display_override: It overrides the _display() method.
  • cache_override: It enables calling of the user-defined method instead of _display_cache() method which is available in the Output Library. This permits you for using your own cache display mechanism.
  • post_system: It is called soon after the final rendered page has been submitted to the web browser, at the end of system execution when the final data has been sent to the browser.

15.What is Command-Line Interface(CLI)?


    Command-Line Interface or CLI is a text-based interface for interacting with computers through a set of commands.

16.What is third party in CodeIgniter?


    So, if you are using CodeIgniter then you have to put that third party API libraries within the same library folder where you have kept or created your own application libraries. It is recommended to place third party packages in the application/third_party folder.

17.What is meant by a library?


    Libraries are packages created in PHP that give higher-level abstractions and thus contribute to faster development. This removes the necessity of focusing on small, minute details by taking care of those by themselves.

18.How can you load a library in CodeIgniter?


    For example, to load the Form Validation Library you would do this: $this->load->library(‘form_validation’); Once initialized you can use it as indicated in the user guide page corresponding to that class.

19.What is CSRF token in CodeIgniter?


  • CSRF(Cross-Site Request Forgery) token is a randomly generated value that gets modified with every HTTP request sent by webform.
  • A CSRF attack forces a browser of the logged-on victim for sending a forged HTTP request, including the session cookie of the victim and other information related to authorization, to a web application. A CSRF token is used for setting or activating the protection in CodeIgniter.
  • CSRF token is saved in the user’s session when it is added in the website form. When we submit the form, the website compares both submitted tokens and saved tokens in the session. If they are the same, a request is considered valid. When the page gets loaded token value will also be changed each time. Thus it becomes difficult for the hackers to identify the current token.

20.How to set CSRF token?


    To set CSRF, you have to set the corresponding config value as true in your application/config/config.php file.

    Syntax : $config[‘csrf_protection’] = TRUE;

    If you use the form helper, the form_open() method will automatically insert a hidden CSRF field in your forms.

21.How to extend the class in CodeIgniter?


    You have to create a file with the name Example.php under application/core/ directory and declare your class with the below code:-

    • Class Example extends CI_Input {
    • // Write your code here
    • }

22.What is the difference between Laravel and CodeIgniter?


Based on
Database model It is object-oriented. It is relational object-oriented.
Built-in module It comes along with a built-in module. It does not come with a built-in module.
Structure Follows MVC structure of filing with a command-line tool known as Artisan. Follows the MVC structure but it provides easier boarding based on object-oriented programming.
Development and Template It is a good option for front-end developers and it comes along with the Blade template engine. It is easier to use and there is no template engine provided.
Utilized by OctoberCMS, Laracasts PyroCMS, Expression engine.
Libraries Provide their own official documentation which is very helpful. Provides a lot of built-in functionality.
Routing Supports Explicit routing Supports both Explicit and Implicit routing.

23.List various databases supported by the CodeIgniter framework.


    Following Databases are supported by the CodeIgniter framework:-

  • MySQL (version 5.1+) database that uses MySQL (deprecated), mysqli, and PDO drivers
  • Oracle database that uses oci8 and PDO drivers
  • PostgreSQL database that uses Postgre and PDO drivers
  • ODBC database that uses ODBC and PDO drivers
  • SQLite database that uses SQLite version 2, SQLite3 version 3, along with PDO drivers
  • MS SQL database that uses Sqlsrv (version 2005 and above), MsSQL, and PDO drivers
  • Interbase/Firebird database that uses iBase and PDO drivers
  • CUBRID database that uses Cubridand PDO drivers

24.What is the work of anchor tag in CodeIgniter?


  • Anchor tag creates a standard HTML anchor link based on the URL of your local site.
  • Syntax: anchor($uri = ”, $title = ”, $attributes = ”)
  • Here, $uri represents a URI string, $title represents an anchor title and $attributes represents an HTML attributes. It returns an HTML hyperlink (anchor tag) of string type.
  • The first parameter can have any segments you would like to append to the URL. These segments can be a string or an array.
  • The second parameter is the text that will be displayed with a link. The URL will be used in case you leave it blank.
  • The third parameter can contain an attribute list you would like added to the link. The attributes can be a string or an associative array.

25.Explain CodeIgniter E-mail library.


    Features of Email Class in CodeIgniter are given below:-

    • Multiple protocols such as Mail, Sendmail, and SMTP.
    • TLS and SSL Encryption for SMTP.
    • CC and BCCs.
    • Multiple recipients.
    • Attachments.
    • HTML or Plain-text email.
    • Priorities.
    • Word wrapping.
    • BCC Batch Mode, enabling larger e-mail lists to be broken into smaller BCC batches.
    • Email Debugging tools.

26.How to send an E-mail using CodeIgniter?


    Sending an email is a simple process here. You can configure an email on the fly or set your preferences in the app/Config/Email.php file. A basic example for demonstrating how you might send email is given below:-

  • $email = \Config\Services::email();
  • $email->setFrom(‘’, ‘Your Name’);
  • $email->setTo(‘’);
  • $email->setCC(‘’);
  • $email->setBCC(‘’);
  • $email->setSubject(‘Email Test’);
  • $email->setMessage(‘Testing the email class.’);
  • $email->send();

27.How to deal with Error handling in CodeIgniter?


    CodeIgniter enables you to develop error reporting into your applications by using the below-given functions. Also, it has a class dedicated to error logging that permits messages related to error and debugging to be saved as text files.Functions related to error handling are:-

  • This function will display the error message provided by the application/errors/errorgeneral.php template.
  • show_error(‘message’ [, int $statuscode= 500 ] )

  • This function shows the 404 error message supplied to it by using the application/errors/error404.php template.
  • show_404(‘page’ [, ‘logerror’])

  • This function permits you to write messages onto your log files. You must provide anyone among three “levels” in the first parameter that indicates the message type (debug, error, info), with the message itself in the second parameter.
  • log_message(‘level’, ‘message’)

28.Explain the default URL pattern used in CodeIgniter.


  • CodeIgniter will make use of a “segment-based” approach instead of a “query string-based” approach.
  • CodeIgniter framework has four main parts in the default URL pattern. First, we have the name of the server, and next, we have the name of the controller class followed by name of the controller function and function parameters at the end. Codeigniter is accessed using the URL helper. The basic URL structure is: http://servername/controllerName/controllerFunction/parameter1/parameter2/…/parametern

29.How you can add or load a model in CodeIgniter?


  • In CodeIgniter, models are loaded as well as called inside your controller methods. For loading a model, you must use the below-given method: $this->load->model(‘name_of_the_model’);
  • Include the relative path from the directory of your model, if your model is placed inside a sub-directory. Consider an example, you have a model which is placed at application/models/blog/AllPosts.php you can load it by using: $this->load->model(‘blog/AllPosts’);

30.Explain the CodeIgniter framework.


    The CodeIgniter application is based on the MVC (Model – View – Controller) model, which separates the application logic from the presentation view. Because of presentation view separation from the PHP scripting, it allows your web pages for script minimization.

CodeIgniter framework
CodeIgniter framework

31.Explain how to prevent CodeIgniter from CSRF(Cross Site Request Forgery).


    There are many ways to protect CodeIgniter from CSRF, one method of doing this is to use a hidden field in every form on the website. This hidden field is considered as CSRF token, it is a random value that changes with each HTTP request sent. After gets inserted into the website forms, it will be saved in the user’s session as well. So, when the user submits the form, the website checks whether it is the same as the one that was saved in the session. If it is the same then, the request is authorized.

Course Curriculum

Develop Your Skills with CodeIgniter Certification Training

Weekday / Weekend BatchesSee Batch Details

32.What is the security parameter for XSS in CodeIgniter?


  • Codeigniter has got a Cross-Site Scripting(XSS) hack prevention filter. This filter either automatically runs or you can run it based on item, to filter all data related to POST and COOKIE.
  • The XSS filter will target the frequently used methods to trigger JavaScript code or other types of code that attempt to hijack cookies or do any other malicious activity. If it identifies anything suspicious or anything disallowed is encountered, then it will convert the data to character entities.
  • To filter data through the XSS filter, we will make use of the xss_clean() method as given below:
  • $data = $this->security->xss_clean($data);

33.What is plugin in Codeigniter?


    Plugins work almost identically to Helpers. Plugins should be saved to your system/plugins directory or you can create a folder called plugins inside your application folder and store them there. … CodeIgniter will look first in your system/application/plugins directory.

34.List all the auto-loadable resources available in CodeIgniter.


    The below-given items can be automatically loaded in CodeIgniter:-

  • Classes obtained in the directory named libraries
  • Custom config files obtained in the directory named config
  • Helper files obtained in the directory named helpers
  • Models obtained in the directory named models
  • Language files obtained in the directory named system/language

35.What do you mean by the controller in CodeIgniter?


  • The mediator present between the model and the view for processing the HTTP request and is used for generating a web page is called a controller. It is considered as the center of each HTTP request that exists on the web application of the user.
  • Consider the following URL in this reference: projectName/index.php/welcome/
  • In this URL, the CodeIgniter is trying to find the welcome.php file and the Welcome class.

36.Why is there a need to configure the URL routes?


    Changing the URL routes has many benefits such as:-

  • From the SEO(Search Engine Optimization) point of the view, to make URL SEO friendly and obtain more user visits.
  • Hide some URL elements like controller name, function name, etc. from the users for security purposes.
  • Provides different functionality to the specific parts of a system.

37.What are the most prominent features of CodeIgniter?


    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 the Model View Controller (MVC) pattern.
  • It has full featured database classes and support for several platforms.
  • It is extensible. You can easily extend the system by using your libraries, helpers.
  • Excellent documentation.

38.Explain MVC in CodeIgniter.


  • CodeIgniter framework is based on MVC pattern. MVC is a software that gives you a separate logical view from the presentation view. Due to this, a web page contains minimal scripting.
  • Model – The Controller manages models. It represents your data structure. Model classes contain functions through which you can insert, retrieve or update information in your database.
  • View – View is the information that is presented in front of users. It can be a web page or parts the page like header and footer.
  • Controllers – Controller is the intermediary between models and view to process HTTP request and generates a web page. All the requests received by the controller are passed on to models and view to process the information.

39.Explain 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.
  • Here, ModelName is the name of your model file. Remember, the class first letter must be in an uppercase letter followed by other lowercase letters, and it should be the same as your file name. It extends the base CodeIgniter Model so that all the built-in methods of parent Model file gets inherited to the newly created file.

40.How can you connect models to a database manually?


    To connect database manually use following syntax, $this->load->database();

41.Explain views in CodeIgniter.


  • 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 call directly, and they have to be loaded in the controller’s file.
  • Create a file and save it in application/views folder. For example, we have created a file Firstview.php,

42.How can you load a view in CodeIgniter?


    The 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’);

  • Write your view’s page name in the bracket. You don’t need to specify .php unless you are using some other extension.
  • Now, go to your controller file (Main.php) and write this code as shown below.

43.Explain controller in CodeIgniter.


  • A controller is the intermediary between models and views to process the HTTP request and generates a web page. It is the center of every request on your web application.
  • Look at the above snapshot, controller’s file name is Main.php (the first letter has to be in uppercase), and the class name is Main (the first letter has to be in uppercase).

44.What is the default controller in CodeIgniter?


    The file specified in the default controller loaded by default when no file name is mentioned in the URL. By default, it is welcome.php which is the first page to be seen after installing CodeIgniter.

default controller in CodeIgniter

45.How will you call a constructor in CodeIgniter?


    To use a constructor, you need to mention the following line of code,


46.What is the default method name in CodeIgniter?


    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.

47.Explain the remapping method calls in CodeIgniter.


    The 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.

48.What is a helper in CodeIgniter?


    Helpers are the group of functions that are used to assist the user to perform specific tasks.

49.How can a helper file be loaded?


  • URL Helpers: used to create the links.
  • Text Helpers: used for text formatting.
  • Cookies Helpers: used for reading and setting cookies.

50.How can you load multiple helper files?


    To load multiple helper files, specify them in an array,


    array(‘helper1’, ‘helper2’, ‘helper3’)


51.Explain the CodeIgniter library.


    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.

52.Where is a newly created library stored in CodeIgniter structure?


    It should be placed in application/libraries folder.

53.Can you extend native libraries in CodeIgniter?


    Yes, we can add some extended functionality to a native library by adding one or two methods. It replaces the entire library with your version. So it is better to extend the class. Extending and replacing is almost identical with only following exceptions.

54.How can you extend a class in CodeIgniter?


    You have to build a file name application/core/MY_Input.php and declare your class with Class MY_Input extends CI_Input {}to extend the native input class in CodeIgniter.

55.What is routing in CodeIgniter?


    Routing is a technique by which you can define your URLs according to the requirement instead of using the predefined URLs. Routes can be classified in two ways, either using Wildcards or Regular Expressions.

56.What are CodeIgniter drivers?


    These are a particular type of library that has a parent class and many child classes. These child classes have access to the parent class, but not to their siblings. Drivers are found in system/libraries folder.

57.How to initialize a driver in CodeIgniter?


    To initialize a driver, write the following syntax,


    Here, class_name is the driver name.

58.How to create a driver in CodeIgniter?


    There are three steps to create a driver:-

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

59.How to connect multiple databases in CodeIgniter?


    To connect more than one database simultaneously, do the following,

  • $db1 = $this->load->database(‘group_one’, TRUE);
  • $db1 = $this->load->database(‘group_two’, TRUE);

60.How can you print SQL statement in CodeIgniter model?



61.What are CodeIgniter security methods?


    CodeIgniter security methods help to create a secure application and process input data. The methods are given below:

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

62.How can the CodeIgniter be prevented from CSRF?


    There are the various ways by which, we can prevent CodeIgniter from CSRF. The most used method is using the hidden field in each page of the website. The hidden field is stored in the user’s session. The filed is changed with every HTTP request. The user can be detected in its every request to the website. The hidden value is always compared with the one saved in the session. If it is the same, the request is valid.

63.What is the latest version of CodeIgniter?


    Although CodeIgniter 3.1.11 is the current version that is used alongside PHP 5.6+, the team is developing CodeIgniter 4, an upcoming version that will be used for web development in PHP 7.2.

64.How do you check the version of CodeIgniter you are using?


    There are 2 ways to do this. The first is to run the following line of code:

  • The second way is to navigate to the system/core/CodeIgniter.php directory and run the following code:
  • define(‘CI_VERSION’, ‘2.1.4’);

65.How do you auto-load a model that is to be used globally?


    Open the application/config/autoload.php file and add your model to the autoload array. This way, your model will be loaded automatically when the system is initialized.

Course Curriculum

Get JOB Oriented CodeIgniter Training for Beginners By MNC Experts

  • Instructor-led Sessions
  • Real-life Case Studies
  • Assignments
Explore Curriculum

66.Which databases can be used in CodeIgniter?


PostgreSQL Postgre, PDO
Oracle Oci8, PDO
SQLite SQLite, sqlite3, PDO
CUBRID Cubridand, PDO
Interbase/Firebird iBase, PDO

67.Where are all libraries located in CodeIgniter?


    All the pre-packaged libraries developed by CodeIgniter are available in the system/libraries directory.

68.How do you load multiple libraries at the same time?


    The process is similar to loading multiple helper files. You use the same line of code for loading one library but replace the parameter with an array.

69.What are some naming conventions you should follow while creating libraries?


    There are 3 conventions you should follow to make your own life easier:-

  • Capitalize all file names, e.g. Sampleclass.php
  • Capitalize all class declarations, e.g. class Sampleclass
  • Choose the same name for your files and classes

70.What is the basic prototype of a class file?


    Here is the basic prototype of a class file:-

    • defined(‘BASEPATH’) OR exit(‘No direct script access allowed’);
    • class Someclass {
    • public function some_method() { }
    • }

71.What is the method to extend a class in CodeIgniter?


    To extend a class, you have to create a file named MY_Input.php in the application/core/ directory with the declaration:-

  • Class MY_Input extends CI_Input { }
  • Note that once again, the name of the class and file has been kept consistent.

72.What is an example of a URL routing different from the default one?


    By default, CodeIgniter follows a standard structure for the URL which gives the first segment to the class and the second to the function. This is what it looks like:-

  • However, you can choose to have a different structure. Here is one example:

  • In this example, the second segment is kept for a product ID instead of a method.

73.How do you specify your own routing rules?


    First, you have to navigate to application/config/routes.php, and locate the array called $route. Next, you can use either a wildcard entry or a regular expression.

74.What are wildcards and regular expressions?


    You can have two kinds of wildcards:-

  • Matching only numbers through: num-series.
  • Matching only characters through: any-series.

75.What is the purpose of configuring URL routes?


    There are several reasons why you would configure URL routes:-

  • It can increase the page visits to your website through better search engine visibility.
  • It can help hide the complex expressions from your users.

76.What are hooks in CodeIgniter?


    Hooks are features that allow you to manipulate the way CodeIgniter normally executes its program, without going into the relevant files and meddling with the code.

77.How do you enable hooks in CodeIgniter?


    Navigate to the application/config/config.php file and switch the following setting to ‘TRUE’ as shown below:-

  • $config[‘enable_hooks’] = TRUE;

78.How can you make use of a driver in CodeIgniter?


    You have to initialize it inside the controller using the following line of code:-

  • $this -> load -> driver(‘class_name’);

79.How can you create a driver in CodeIgniter?


    You have to take care of 3 things if you want to make a driver:-

  • Create a file name such as ‘Driver_name.php’
  • Create a list of drivers inside this file
  • Write the code for each individual driver

80.What is the method to link multiple databases in CodeIgniter?


    Here is how you could connect multiple databases at the same time (simultaneously):-

  • $db1 = $this -> load -> database(‘group_one’, TRUE);
  • $db1 = $this -> load -> database(‘group_two’, TRUE);

81.What are security methods in CodeIgniter?


    CodeIgniter has several ways of implementing security in your application and protecting the raw input data fed to your program. Here are 3 methods:-

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

82.How to Do You Link Images From a View in Codeigniter?


    To link images from a view in a codeigniter first use an absolute path to the resources required and link the image from a view in codeigniter /css/styles.css /js/query.php /img/news/566.gpg

83.How Can You Extend the Class in Codeigniter?


    To extend a native input class the user must first build a file which is to be named application/core/MY_Input.php And then proceed to declare the class with Class MY_Input extends CI_Input { }

84.Have you ever heard about csrf attacks?


    Yes, Cross-Site Request Forgery (CSRF) is an attack that forces an end user to execute unwanted actions on a web application in which they’re currently authenticated.

85.Do you think a csrf token should only be generated after authentication ?


    No, they should be created before authentication too.

86.Difference between XSS and CSRF ?


 XSS versus CSRF

87.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’] = “”


    $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]

88.What are 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.

89.How to read session in CodeIgniter?


    Use $this->session->userdata(); method of session class to read session data in CodeIgniter:-


  • $this->session->userdata(‘your_key’); You can also read a session data by using the magic getter of CodeIgniter Session Class.

90.How to write 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.

91.How to remove session in CodeIgniter?


    Session’s Class unset_userdata() method is used to remove a session data in CodeIgniter.

92.How to get last inserted id in CodeIgniter?


    CodeIgniter DB Class insert_id() method is used to get last insert id.

93.What is the CLI?


    CLI is a text-based command-line interface for interacting with computers via a set of commands.

94.Why we use CLI in Codeigniter?


    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!

95.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)
  • Sample Usage:-

  • redirect(‘/posts/13’, ‘New location’, 301)

96.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.

97.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.

98. How to set or get config variables in Codeigniter?


  • Set Config Value: $this->config->set_item(‘mainURL’,’’);
  • Get Config Value: $mainURL = $this->config->item(‘mainURL’);
  • Example Config Value: Read Also: Codeigniter 3 Datatables Ajax Example From Scratch.

99.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);
API Testing Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

100.How to implement validations in Codeigniter?


    You can implement form validations in Codeigniter using a form_validation library.

validations in Codeigniter

Are you looking training with Right Jobs?

Contact Us

Popular Courses

Get Training Quote for Free