CodeIgniter Interview Questions

CodeIgniter is an open-source MVC based framework for PHP. It is a loosely coupled framework that we can use for the rapid development of websites and mobile APIs.

1) How to check the version of the CodeIgniter framework?

  • In system/core/CodeIgniter.php, check CI_VERSION constant value define(‘CI_VERSION’, ‘3.0.6’);

2) How to set CSRF token in CodeIgniter?

  • CSRF is used to set the protection in CodeIgniter. To set CSRF, you have to put the corresponding config value True.
  • Syntax: $config['csrf_protection'] = TRUE;

3) How many types of messages you can log in to CodeIgniter?

  • There are three message types in Codeigniter. They are :
    • Error Messages. These are actual errors, such as PHP errors or user errors.
    • Debug Messages. These are messages that assist in debugging. For example, if a class has been initialized, you could log this as debugging info.
    • Informational Messages. These are the lowest priority messages, simply giving information regarding some process.

4) In CodeIgniter frameworks where logs are saved?

  • By default, all logs are stored in logs/ directory.

5) How to enable error logging CodeIgniter?

  • To enable error logging you must set the “threshold” for logging in "application/config/config.php". Also, your logs/ must be writable.
  • $config['log_threshold'] = 1;

6) In which files CodeIgniter routes are defined?

  • Codeigniter routes are defined in your "application/config/routes.php" file.

7) List the resources that can be autoloaded in CodeIgniter?

  • The following items can be loaded automatically:
    • Classes found in the libraries/ directory
    • Helper files found in the helpers/ directory
    • Custom config files found in the config/ directory
    • Language files found in the system/language/ directory
    • Models found in the models/ folder
  • To autoload resources, open the application/config/autoload.php file and add the item you want loading to the autoload array.

8) Why CodeIgniter is called a loosely based MVC framework?

  • Codeigniter is Called a loosely based MVC framework, this is because unlike others the controllers’ classes such as models and views are not mandatory in CodeIgniter. Moreover, one can modify CodeIgniter to utilize HMVC as well.

9) URL pattern in CodeIgniter?

10) What is is_cli() method does in CodeIgniter?

  • In Codeigniter is_cli() method is used to check requests is from the command line or not.
  • Returns TRUE if the application is run through the command line and FALSE if not.

11) How set or get config variables in CodeIgniter?

  • In the CodeIgniter framework by default, all config variables are located at the “application/config/config.php” file.
  • Below is the way to set or get a config variable in Codeigniter
  • // Setting a config variable dynamically
  • $this->config->set_item('variable_name', value);
  • // Getting value of config variable in Codeigniter.
  • $this->config->item('variable_name');

12) How to get random records in MySQL using CodeIgniter?

  • order_by function is used to order the records from a table in CodeIgniter.
  • // Getting random rows from database in CodeIgniter
  • $this->db->select('*');
  • $this->db->from('table_name');
  • $this->db->order_by("column_name", "random");
  • $result = $this->db->get()->result();

13) How to delete records 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);

Comments

Popular posts from this blog

Basic Terminology

Introduction To PHP

What is normalization in DBMS?