We know that PHP is the most powerful language in the present time, but to execute it, developers use many frameworks. As it is easier for developers to combine the code with popular frameworks without adding additional code. From many frameworks, CodeIgniter is a widely used framework for PHP. Let’s see more about CodeIgniter and its features.
CodeIgniter is used to build dynamic web sites with PHP. It is an open open-source software rapid development web framework. It is based on the famous model-view-controller (MVC) development pattern. Besides, the model and views are optional in CodeIgniter. Moreover, Hierarchical Model View Controller (HMVC) can be used by modifying the CodeIgniter which helps the developer to manage the modular grouping of Models, Controller and View arranged in a sub-directory format. Coupling with this, the CodeIgniter is most preferable compared to other PHP frameworks due to its fascinating feature of speed.
The above is an overview of CodeIgniter and its some features. But if you want to know more about CodeIgniter to compete in an interview and get hired, then you must read our online interview questions. Below is the best collection of CodeIgniter interview questions that will definitely help you to get your dream job.
11th Dec, 2019
Below are few major features of Codeigniter
Q1. What is Codeigniter in PHP?
CodeIgniter is a PHP based web framework for developing web applications quickly. It is an MVC based architecture that makes faster dynamic application development. An open-source framework released in 2006, CodeIgniter doesn’t force MVC (i.e.), models and views are optional while the controller is necessary for web development. CodeIgniter has a very small footprint and yet offers exceptional performance. Built for developers who need fast and simple web development, CodeIgniter offers libraries for uploading files, sending emails, managing sessions, etc. Works on multi-platform, CodeIgniter is now developed by the British Colombia Institute of Technology.
Q2. Enlist few benefits of CodeIgniter?
Developed using PHP, CodeIgniter offers the benefits of PHP web development along with its benefit such as,
Q3. What are hooks in Codeigniter?
Hooks in CodeIgniter is one of its useful features that let the user to change the working of the framework without tapping into the core files. Hooks can be used to do run a script at a particular path in the time of execution without touching the core files. Eg: to check if the user is signed in or not before the controller is executed.
To enable Hook in your application, go to the path “application/config/config.php”, and enable the setting as true.
$config['enable_hooks'] = TRUE;
To define a Hook in your application, go to the path “application/config/hooks.php” and specify the hook array.
$hook['pre_controller'] = array( 'class' => 'MyClass', 'function' => 'Myfunction', 'filename' => 'Myclass.php', 'filepath' => 'hooks', 'params' => array('beer', 'wine', 'snacks') );
Index(“pre_controller”) is defined based on the point where you want to use the hook.
class is the name of the class file that you should invoke at that point.
function is the method in the class that you should call.
filename is the path where the specified class exists.
filepath is the name of the directory where your hook script is located.
params is the arguments that you wish to pass with your scrip.
Q4. How to check version of Codeigniter?
There are two ways to check the CodeIgniter version,
Run the following code to know your version.
The second way is to go to the path “system/core/CodeIgniter.php”, and check,
Q5. What is csrf in Codeigniter?
CSRF is a security class that is used to create a secure application. Expanded as Cross-site request forgery, and you can enable it by changing the file found in the path “application/config/config.php” and setting the following config true,
$config['csrf_protection'] = TRUE;
If you’re working with the form in CodeIgniter the form_open() function by default will insert the csrf field which is hidden in your form. You can get csrf hash and token name by using the function get_csrf_hash() and get_csrf_token_name(). Csrf token is regenerated every time form is submitted.
The main use of CSRF class is to prevent CSRF attacks in your web application.
Q6. What are inhibitor in Codeigniter?
Inhibitor in CodeIgniter is an error handling class. It uses the native PHP error handling functions like set_exception_handler, set_error_handler, and register_shutdown_function to handle errors like parse error, exception error, and fatal error.
All the error handler is a user defined error handler.
set_error_handler("myErrorHandler"); set_exception_handler("myException"); register_shutdown_function('endScript');
Q7. How to get current url in Codeigniter?
CodeIgniter provides a URL helper library to get the URL of the existing page and base page. To get URL, use current_url() function. But before using the current_url() function, you should load the URL helper.
$this->load->helper('url'); // load the url helper
$currentURL = current_url(); // get the url print_r($currentURL); // print the url
Q8. Explain timezone helper in Codeigniter?
Time zone reference in CodeIgniter comes under the data helper file that helps in working with the dates. To set the time zone, one should extend the date helper class.
$timezone = config_item('time_reference');
To change the default time zone, go to the config.php file and set the time reference.
$config[‘time_reference’] = ‘Asia/Dhaka’; Or date_default_timezone_set('Asia/Dhaka');
Q9. How to set base url in Codeigniter?
The base URL of the CodeIgniter can be set in the config.php file in the following path, Application/config/config.php
$config[‘base_url’] = ‘http://example.com’;
Typically, it is the URL to the CodeIgniter root. If the base URL is not set by the user, then CodeIgniter will try to guess the installation path, domain, and set it as the URL. This auto-detection of the base URL should not be used in the production process.
Eg: $config['base_url'] = 'http://your-domain.com';
Q10. How to add library in Codeigniter?
CodeIgniter provides a rich set of libraries that are used to improve the development process of our web application. The library is located in the folder system/library. We can just load the library and use it in our application.
$this->load->library('class name'); //syntax to load the library
Here, ‘class name’ is just the name of the library that we should use in our application.
$this->load->library('email'); //example of a loading email class library in our application.
Loading multiple libraries is also possible by passing the name of the library as an array to the library() function.
$this->load->library(array('email', 'table')); //example of loading multiple libraries.
Q11. List different types of cache supported by Codeigniter?
CodeIgniter supports various types of caching and caching is essential for improving your application speed and reducing the server overhead. The types of caching method in CodeIgniter are,
Abbreviated as Alternative PHP Cache, it is used to store bytecode at an execution time. So, the bytecode can be reused every time the program is recompiled.
$this->load->driver('cache'); //loading APC cache driver. $this->cache->apc->save('foo', 'bar', 10); //saving data into APC cache.
This type of caching allows for pieces of your files to be cached. You need to be careful with this because there is a chance that IO disks will negate positive gains by caching.
$this->load->driver('cache'); //loading file cache driver. $this->cache->file->save('foo', 'bar', 10); //save some data into file cache.
It is a distributed caching system that stored database objects in dynamic memory to improve the performance. Memcached servers can be specified in the memcached.php config file that is located in the application/config directory.
$this->load->driver('cache'); //loads the memcached driver $this->cache->memcached->save('foo', 'bar', 10); //saves some data into mamcache
In all the above cache, the specific drivers need not be mentioned to load the cache.
It stores no data. It stores your caching code in the place where it doesn’t support the chosen cache.
Q12. How to write truncate query in Codeigniter?
Truncating a table deletes all its data from it. With the QueryBuilder class in the CodeIgniter, you can truncate the table. If the truncate command is not available, then CodeIgniter will use the “DELETE FROM” table command.
There is two ways to truncate a table.
$this->db->from('mytable'); $this->db->truncate(); Or $this->db->truncate('mytable');
Q13. How to get last inserted id in CodeIgniter?
In Database programming, it is often important to get the id of the last inserted item. CodeIgniter framework allows you to get the last inserted id using the function insert_id().
It is one of the functions in the database library provided in the CodeIgniter framework.
$input = ['name'=>'Priyag', 'description'=>'The name is Priyag']; //creating an input data $this->db->insert('items', $input); //inserting the input data $insertId = $this->db->insert_id(); //returns the id of the last inserted data.
Q14. How to use orderby clause in CodeIgniter?
The order_by clause statement returns the resulting set in ascending, descending, or in some random order. order_by clause is present in the CodeIgniter query builder class. order_by() clause was called as orderby().
The above statement is an example of the order_by clause. The first parameter “title” is the name of the column that you want to get sorted. The second parameter “DESC” lets you sort the column in descending order.
Multiple order_by statements can also be made.
$this->db->order_by('title', 'DESC'); $this->db->order_by('name', 'ASC');
Random ordering can also be done, but the first parameter is ignored unless you specify a numeric seed value.
$this->db->order_by(42, 'RANDOM'); // sorts by order rand(42)
Q15. What is default controller in CodeIgniter?
A controller is nothing but a class that is associated with a URI. When a URI is not specified, CodeIgniter can be specified to load a default controller. To load a default controller, go to the following path “application/config/routes.php”, and open routes.php file. In the routes.php file, set the default controller variable here.
$route['default_controller'] = 'dClass';
Here, dClass is the name of the controller class that will be loaded by default.
It supports more database.
It supports the limited database.
It follows the relational object-oriented
It follows the object-oriented method.
The template language is PHP proprietary
The template language is Blade Template Engine
It is for those who use a simple tool kit
It is for those who need an elegant and modest kind of toolkit
It is component driven
It is object-oriented event-driven functional
It supports explicit and implicit routing
It supports explicit routing
It does not support built in the modular feature
It supports built in the modular feature
It does not support the HTTP route sufficiently.
It supports HTTP routes
Programming language is PHP
Programming language is PHP.
It is under the MIT license
It is under the BSD license
Template language of CodeIgniter is PHP proprietary
Template language of Yii is PHP smarty twig
It supports component-oriented
It supports object-oriented event-driven.
CodeIgniter is trustworthy and lightweight.
It offers PHP developer the easiest way to utilize modular programs and get a specific function through the framework.
PHP developer finds it easy in CodeIgniter to utilize modular programs and get a specific function through the framework.
It fits almost with all operating systems, web servers and platforms.
CodeIgniter help PHP developers to create a web application with high-end functionalities and additional features. It is possible due to the In-built libraries and resources provided by the CodeIgniter.
This helps the programmers to build web applications in a secured manner.
CodeIgniter helps the developer to create rear end and the front end of the application efficiently.
It offers easy customization and configuration of files and also supports hassle-free migration
Developers are able to reduce the amount of code required to develop an application of PHP.
CodeIgniter is quite useful in detecting the error and neutralizing it. It is a very user- friendly framework. It provides the developer's bug handling and debugging messages.
CodeIgniter provides the form validation feature to the developers. By this, they are able to write the code in a single line. You are able to use Effective validation framework system to write codes.
It is easy to edit the existing CodeIgniter files which are helpful for the developers to create what they want. Beginners can use this to avoid confusion.
You can use the migration aspect for the management of the database scheme. It is very easy to migrate server in CodeIgniter.