InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Why is there a need to configure the URL routes? |
|
Answer» Changing the URL routes has many benefits such as:
Conclusion: Freedcamp, Nissan, Bonfire, Buffer, etc. are some of the websites that use the CodeIgniter framework. There is a great amount of demand for PHP developers with CodeIgniter skills. This SET of interview questions will DEFINITELY help you excel in the CodeIgniter job interview. We hope these interview questions and answers on CodeIgniter will assist you to crack the relevant interview. References: “Professional CodeIgniter” by Thomas Myer. “CodeIgniter for Rapid PHP Application Development” by David Upton. |
|
| 2. |
What do you mean by the controller in CodeIgniter? |
Answer»
|
|
| 3. |
List all the auto-loadable resources available in CodeIgniter. |
Answer»
|
|
| 4. |
What is the default controller in CodeIgniter? |
Answer»
|
|
| 5. |
What is the security parameter for XSS in CodeIgniter? |
Answer»
This function is used only when you are submitting data. The second Boolean parameter is optional and used to check the image files for the XSS attacks. This is very useful for FILE upload. If its value is true, that means the image is safer and not otherwise. |
|
| 6. |
Explain CodeIgniter folder structure. |
|
Answer» The CodeIgniter folder structure is given below:
|
|
| 7. |
What are the sessions in CodeIgniter? How to handle sessions in CodeIgniter? |
|
Answer» In CodeIgniter, you are allowed to maintain a user’s “state” by Session class and keep an eye on their activity while they browse your website.
If you want to add a single user data at a TIME, set_userdata() supports this syntax: $this->session->set_userdata('demo_username', 'demo_value');
Unset an array of item keys: $arr_items = array('name_of_user', 'email');$this->session->unset_userdata($arr_items); |
|
| 8. |
Explain how to prevent CodeIgniter from CSRF(Cross Site Request Forgery). |
|
Answer» 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. |
|
| 9. |
How to pass an array from the controller to view in CodeIgniter? |
|
Answer» A view is a webpage that shows each element of the USER interface. It cannot be called directly, you need to load the views via the controller. You can pass an array from the controller to view in CodeIgniter using below given steps:
Create a new text file and name it ciblogview.php. Save the created file in the application/views/ directory. Open the ciblogview.php file and add the below-given code to it: <html><head> <title>Blog</title></head><body> <h1>Welcome to Blog in CodeIgniter</h1></body></html>
Loading a view is executed using the following syntax: $this->load->view('name'); Where ‘name’ represents the name of the view. The below code CREATES a controller named Blog.php. This controller has the method for loading the view. <?phpclass Blog extends CI_Controller { public function index() { $this->load->view('ciblogview'); }}?>
You are allowed to paste the below-given controller code within your controller file or put it in the controller object. $data['mega_header'][] = (object) array('title' => 'image portfolio' , 'img' => 'https://complete_image_path' );$this->load->view('multiple_array', $data);Arrays are displayed as a brick[‘…’] and OBJECTS as an arrow(->). You are allowed to ACCESS an array with the brick[‘…’] and object using the arrow (->). Therefore, add the below-given code in the view file: <?php if (isset($mega_header)){ foreach ($mega_header as $key) { ?> <div class="header_item"> <img alt="<?php echo($key['title']); ?>" src="<?php echo($key->img); ?>"/> </div> <?php } }?>
Usually, data transfer from the controller to view is done through an array or an object. The array or the object is passed as the second parameter of the view load method similar to the below-given method: $data = array( 'title' => 'TitleValue', 'heading' => 'HeadingValue');$this->load->view('ciblogview', $data);The controller will look like this: <?php class Blog extends CI_Controller { public function index() { $data['title'] = "TitleValue"; $data['heading'] = "HeadingValue"; $this->load->view('ciblogview', $data); }}?>The view file will look like this: <html><head> <title><?php echo $title;?></title></head><body> <h1><?php echo $heading;?></h1></body></html> |
|
| 10. |
Explain the CodeIgniter framework. |
|
Answer» 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.
|
|
| 11. |
How you can add or load a model in CodeIgniter? |
Answer»
|
|
| 12. |
Explain the default URL pattern used in CodeIgniter. |
Answer»
Here, interviewbit.com is a server name, a user is a controller class that needs to be invoked, an edit is an action or method, and suresh is an optional action parameter that is passed to CONTROLLERS. |
|
| 13. |
How to deal with Error handling in CodeIgniter? |
|
Answer» 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:
|
|
| 14. |
Explain CodeIgniter E-mail library. How to send an E-mail using CodeIgniter? |
| Answer» $email = \Config\Services::email();$email->setFrom('your@interviewbit.com', 'Your Name');$email->setTo('someone@interviewbit.com');$email->setCC('another@another-example.com');$email->setBCC('them@their-example.com');$email->setSubject('Email Test');$email->setMessage('Testing the email class.');$email->send(); | |
| 15. |
What is the work of anchor tag in CodeIgniter? |
Answer»
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.
|
|
| 16. |
List various databases supported by the CodeIgniter framework. |
|
Answer» Following Databases are supported by the CodeIgniter FRAMEWORK:
|
|
| 17. |
What is the difference between Laravel and CodeIgniter? |
||||||||||||||||||||||||
Answer»
|
|||||||||||||||||||||||||
| 18. |
How to extend the class in CodeIgniter? |
|
Answer» 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} |
|
| 19. |
What is CSRF token in CodeIgniter? How to set CSRF token? |
Answer»
|
|
| 20. |
What is meant by a library? How can you load a library in CodeIgniter? |
Answer»
|
|
| 21. |
What is Command-Line Interface(CLI)? Why we use CLI in Codeigniter? |
|
Answer» Command-Line Interface or CLI is a text-based interface for INTERACTING with computers through a set of commands. We can use CLI in CODEIGNITER for:
|
|
| 22. |
Give the list of hooks available in CodeIgniter. |
|
Answer» The list of available hook points are given below:
|
|
| 23. |
What are the advantages of CodeIgniter? |
|
Answer» Few advantages of using CodeIgniter is given below:
|
|
| 24. |
How to load a helper in CodeIgniter? |
Answer»
|
|
| 25. |
Explain CodeIgniter Architecture. |
Answer»
|
|