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. For Example:
public function _remap($methodName)
{
if ($methodName === ‘a_method’)
{
$this->method();
}
else
{
$this->defaultMethod();
}
}
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
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.
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.
The class declaration must extend the parent class.
New class name and filename must be prefixed with MY_.
For example, to extend it to native Calendar, create a file MY_Calendar.php in application/libraries folder. Your class declared as class MY_Calendar extends CI_Calendar}
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.
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.
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.
What is a helper in CodeIgniter? How can a helper file be loaded?
Helpers are the group of functions that are used to assist the user to perform specific tasks.
URL Helpers: used to create the links.
Text Helpers: used for text formatting.
Cookies Helpers: used for reading and setting cookies.
What are the XSS security parameters?
XSS stands for cross-site scripting. Codeigniter contains a cross-site scripting hack prevention filter. The XSS filter targets methods to trigger JavaScript or other types of suspicious code. If it detects anything, it converts the data to character entities.
XSS filtering uses xss_clean() method to filer data.
$data = $this->security->xss_clean($data);
There is an optional second parameter, is_image, which is used to test images for XSS attacks. When this parameter is set to TRUE, it doesn’t return an altered string. Instead, it returns TRUE if an image is safe and FALSE if it contains malicious information.
if ($this->security->xss_clean($file, TRUE) === FALSE)
{
//file failed in xss test
}
Explain the folder structure of CodeIgniter.
If you download and unzip CodeIgniter, you get the following file structure/folder structure:
Application
- cache
- Config
- Controllers
- core
- errors
- helpers
- hooks
- language
- libraries
- logs
- models
- third-party
- views
system
- core
- database
- fonts
- helpers
- language
- libraries