What is CodeIgniter and what are its features?
CodeIgniter is PHP opensource framework, based on loosely coupled MVC pattern. It consists of huge libraries, simple interface and logical structure to access these libraries, plugins, and helpers to solve complex logical problems. It’s a lightweight elegant framework which provides faster development rather than writing code from scratch.
It’s appropriate in the following situations to create a project with CodeIgniter.
- Small learning curve.
- Situations where a framework with a small footprint is needed.
- It’s a framework with zero configuration.
- It’s a framework which doesn’t require to stick to strict coding rules.
- Provides high performance and simple coding structure.
- It’s a framework which doesn’t use the command line.
- It provides built-in protection against CSRF and XSS attacks.
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
$config['enable_hooks'] = TRUE;
- It is defined in
application/config/hooks.phpfile. For example:
$hook[‘pre_controller’] = array( ‘class’ => ‘MyHookClass’, ‘function’ => ‘Myhookfunction’, ‘filename’ => ‘MyHookClass.php’, ‘filepath’ => ‘hooks’, ‘params’ => array(‘test’, ‘test1’, ‘webs’) );
In the above code example, the ‘pre_controller‘ hook is called hook point. Various types of hook points are available in CodeIgniter.
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
register_shutdown_function to handle parse errors, exceptions, and fatal errors.
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 |
|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 |
|All built-in helper file names are suffixed with a word||All built-in library files do not have a specific suffix.|
Explain CodeIgniter folder structure.
The CodeIgniter folder structure is given below:
- application: This directory will have your application logic. All of your application codes will be held in this directory. Internal subdirectories in the CodeIgniter directory structure are given below:
- cache – It stores cached files.
- config – It keeps configuration files.
- controller – All application controllers are defined under this controller.
- core – It consists of custom core classes that extend system files. For example, if you create a base controller that other controllers should extend, then you should place it under this directory.
- helpers – This directory will be used for user-defined helper functions.
- hooks – It is used for custom hooks in the CodeIgniter folder structure.
- language – It is used to store language files for applications that use multiple languages.
- libraries – It is used to store custom-created libraries.
- logs – Application log files are placed in this directory.
- models – All application models must be defined under this directory.
- third_party – This is used for custom many packages that are created by you or other developers.
- views – application views will be stored in this directory.
- system: It consists of the framework core files. It is not advised to make any modifications in this directory or put your own application code into this directory. System subdirectories in CodeIgniter are given below:
- core – This is considered to be the heart of the CodeIgniter Framework. All of the core files that construct the framework are located here. If you would like to extend the core file functionality, then you must
- create a custom core file in the application directory. After this, you are allowed to override or add new behavior that you wish. You should never make any changes directly in this directory.
- database – It stores the files such as database drivers, cache, and other files that are needed for database operations.
- fonts – This directory contains fonts and font-related information.
- helpers – This directory consists of helper functions that come out of the box.
- language – It contains language files that are used by the framework
- libraries – It contains the source files for the different libraries that come along with CodeIgniter out of the box.
- user_guide: This directory consists of a user manual for CodeIgniter. You should not upload this directory during application deployment.
- vendor: This directory consists of composer packages source code. The
composer.lockare the other two files related to this directory.
- index.php: This is considered as the entry point into the application. It is placed inside the root directory.