What is codeigniter?
CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications.
What are the features of codeigniter?
- Codeigniter is an open source framework and free to use,
- Model-View-Controller Based System.
- Extremely Light Weight.
- Full Featured database classes with support for several platforms.
- CodeIgniter is Extensible. The system can be easily extended through the use of your own libraries, helpers, or through class extensions or system hooks.
- Excellent documentation.
- Full Featured database classes with support for several platforms, Security and XSS Filtering, Error Logging.
Explain Codeigniter File Structure?
Following are the folder structure:
cache
Config
Controllers
core
errors
helpers
hooks
language
libraries
logs
models
thirdparty
views
core
database
fonts
helpers
language
Explain Application Flow Chart in codeigniter?
The following graphic illustrates how data flows throughout the system:
- The index.php serves as the front controller, initializing the base resources needed to run CodeIgniter.
- The Router examines the HTTP request to determine what should be done with it.
- If a cache file exists, it is sent directly to the browser, bypassing the normal system execution.
- Before the application controller is loaded, the HTTP request and any user submitted data is filtered for security.
- The Controller loads the model, core libraries, helpers, and any other resources needed to process the specific request.
- The finalized View is rendered then sent to the web browser to be seen. If caching is enabled, the view is cached first so that on subsequent requests it can be served.
Explain MVC in Codeigniter?
CodeIgniter is based on the Model-View-Controller development pattern. MVC is a software approach that separates application logic from presentation. In practice, it permits your web pages to contain minimal scripting since the presentation is separate from the PHP scripting.
- The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert, and update information in your database.
- The View is the information that is being presented to a user.
- A View will normally be a web page, but in CodeIgniter, a view can also be a page fragment like a header or footer. It can also be an RSS page, or any other type of “page”.
- The Controller serves as an intermediary between the Model, the View, and any other resources needed to process the HTTP request and generate a web page.
What are the hooks in codeigniter?
CodeIgniter’s Hooks feature provides a means to tap into and modify the inner workings of the framework without hacking the core files. When CodeIgniter runs it follows a specific execution process, diagramed in the Application Flow page. There may be instances, however, where you’d like to cause some action to take place at a particular stage in the execution process. For example, you might want to run a script right before your controllers get loaded, or right after, or you might want to trigger one of your own scripts in some other location.
The hooks feature can be globally enabled/disabled by setting the following item in the application/config/config.php file:
$config[‘enablehooks’] = TRUE;
How you will load a model in codeigniter?
$this->load->model(‘Modelname’);
What are the helpers in codeigniter?
Helpers, as the name suggests, help you with tasks. Each helper file is simply a collection of functions in a particular category. There are URL Helpers, that assist in creating links, there are Form Helpers that help you create form elements,Text Helpers perform various text formatting routines, Cookie Helpers set and read cookies, File Helpers help you deal with files, etc.
Unlike most other systems in CodeIgniter, Helpers are not written in an Object Oriented format. They are simple, procedural functions. Each helper function performs one specific task, with no dependence on other functions.
Loading a helper file is quite simple using the following function:
$this->load->helper (‘name’);
How you will use or add codeigniter libraries?
When we use the term “Libraries” we are normally referring to the classes that are located in the libraries directory and described in the Class Reference of this user guide. In this case, however, we will instead describe how you can create your own libraries within your application/libraries directory in order to maintain separation between your local resources and the global framework resources.
See more at http://ellislab.com/codeigniter/user-guide/general/creatinglibraries.html
How you will work with error handling in codeigniter?
CodeIgniter lets you build error reporting into your applications using the functions described below. In addition, it has an error logging class that permits error and debugging messages to be saved as text files.
show_error(‘message’ [, int $statuscode= 500 ] )
This function will display the error message supplied to it using template application/errors/errorgeneral.php.
show_404(‘page’ [, ‘logerror’])
This function will display the 404 error message supplied to it using template application/errors/error404.php.
log_message(‘level’, ‘message’)
This function lets you write messages to your log files. You must supply one of three “levels” in the first parameter, indicating what type of message it is (debug, error, info), with the message itself in the second parameter.
How to access config variable in codeigniter?
You can access config variable like:
$this->config->item(‘variable name’);
How to unset session in codeigniter?
We can use unsetuserdata to destroy particular session variable
this->session->unset_userdata(‘somename’);
We can use sessdestroy to destroy all session:
$this->session->sess_destroy();
How do you use aliases with autoloading models in codeigniter?
We can auto load model like this:
$autoload[‘model’] = array(array(‘usersmodel’, ‘users’), array(‘newsmodel’, ‘news’), ‘categorymodel’);
How to get random records in mysql using codeigniter?
We can use this:
$this->db->order_by(‘id’,’RANDOM’);
How to print SQL statement in codeigniter model?
We can use this:
$this->db->last_query();
What are the security parameter for XSS in CodeIgniter?
Codeigniter has got a cross-site scripting hack prevention filter. This filter either runs automatically or you can run it as per item basis, to filter all POST and COOKIE data that come across. The XSS filter will target the commonly used methods to trigger JavaScript or other types of code that attempt to hijack cookies or other malicious activity. If it detects any suspicious thing or anything disallowed is encountered, it will convert the data to character entities.
What is the default URL pattern used in Codeigniter framework?
Codeigniter framework URL has four main components in default URL pattern. First we have the server name and next we have the controller class name followed by controller function name and function parameters at the end. Codeigniter can be accessed using the URL helper. For examplehttp://servername/controllerName/controllerFunction/parameter1/parameter2.
How do you get last insert id in codeigniter?
We can get with this.
$this->db->insert_id();
How do you set default timezone in codeigniter?
We can do by adding date_default_timezone_set(‘America/LosAngeles’); in index.php
What are the pros and cons of CodeIgniter?
Pros:
- CodeIgniter helps web developers to find out the errors in programming codes and fix-up the issues instantly in the web applications.
- Superb speed, no lags.
- CodeIgniter provides you user-friendly interface that help developers to create a dynamic, flexible, secure and large web applications effectively in a short span of time.
- Web developers can make use of this powerful framework to customize the configuration files easily and it provides hassle-free migration from source to destination service hosting.
- The framework helps the programmer to create both front-end and rear-end of a web application effectively and easily in a secured manner.
- Programmers can create web applications with additional features and high-end functionalities by using in-built resource and libraries of the CodeIgniter
- Like CakePHP, Codelgniter has massive community support.
Cons:
- Development stagnated for a long time while its previous owner decided what to do with it. Lots of modern PHP practices were adopted during this time, leaving CodeIgniter a bit behind in the times.
- It is difficult-to-understand singleton $CI object acting as a service locator. It is difficult to maintain or modify codes
- Lack of modern namespace + autoloader use. CodeIgniter uses a standard folder and file naming convention that you must adhere to, which limits flexibility.
- Fewer built-in libraries and common tools compared to other frameworks (may actually be considered beneficial for some people who prefer a skeleton framework).