can pass variable as the second parameter of the load->view function. Example:
$data[‘title’]=”My web page”; $data[‘tsp’]=”ussl”;
- Which configuration file is used to autoload resources?
Ans: autoload.php file in system/configuration/config.
- Discuss the php closing tag is codeigniter.
Ans: In codeigniter the php closing tag is optional. If used, any whitespace after the PHP closing tag can result in PHP errors, warning or even blank pages.
- Discuss class, method and variable naming rules in codeigniter.
And: In codeigniter, CLASS name should always have their first letter in uppercase and the rest of the name in lowercase. The class and constructor method should have identical names.
Variable name should always contain lowercase letters, should use underscore separator to separate words and not use camel casing.
- Why short opening tags is not allowed in codeigniter?
Ans: Sometimes in php configuration file, short opening tags is disabled. That’s why CI does not permit short opening tags.
- Disacuss the codeigniter URI.
Ans: CodeIgniter URLs use Uniform Resource Identifiers (URI). Here is a typical CodeIgniter URL:http://mywebsite.ext/index.php/controller/method/parameters
Everything after the index.php segment is used by CodeIgniter to determine what to load. The first segment is the name of the Controller. The second segment is used to determine which function to load—if this is blank then the index function will be used. The final segment will be used to pass any data to the function.
- What is the function of helper files? From where you can load helper files? How to load helper files?
And: Helper files are a collection of functions in a particular group. Helper can be load from model, view and controller. To load helper file we use $this->load->helper(‘filename’);
- What is plugin? How to load plugin?
Ans: Plugins work in almost exactly the same way as Helpers. The main difference is that a plugin should be used to add a single function, instead of a collection of functions. Plugins are stored inside the system/application/plugins/ folder.
To load pluging we use $this->load->plugin(‘name’);
- How to remap function calls?
Ans: We can remap function calls by using a function in our controller called _remap()—this will be called every time that the controller is called, even if a different function is used.
1. What is a library? What do library do?
Ans: A CodeIgniter library is simply a class file that abstracts functionality into easy-to-use functions that take much of the strain off the developer. Libraries abstract out functionality for developers and make it easy to re-use code.
2. Discuss benchmark class.
Ans: The Benchmarking Class is used to calculate the time between two points in our application.
3. Discuss input and security class.
Ans: The Input and Security Class sanitizes all global data and filters all POST and COOKIE data to ensure that only alphanumeric characters are present.
4. How to set automatic filtering in CI?
Ans: We can turn on XSS filtering all of the time and filter everything that comes through the library by changing the following line in the system/application/config/config.php file from:
$config[‘global_xss_filtering’] = FALSE;
$config[‘global_xss_filtering’] = TRUE;
5. How to retrieve get, post, cookie or server data in CI?
Ans: Retrieving POST data:
To retrieve post data, we should use the function shown next. The first parameter is the name of the POST item that we are looking for.
Retrieving GET data:
The function for retrieving GET data is identical to the POST function, except that it only retrieves GET data.
Retrieving COOKIE data:
This function is the same as those listed previously, but will only look in the COOKIE data.
Retrieving SERVER data:
This function is the same as the previous examples, except it only returns SERVER data.
6. What values are stored in a session by default?
Ans: A CodeIgniter session is simply an array containing the following data:
The user’s unique Session ID (this is a randomly-generated number, which is hashed with MD5 for portability, and is regenerated every five minutes)
The user’s IP address
The user’s User Agent string
The “last activity” timestamp.
7. How to add session data and retrieve session data.
Ans: To add data to the session array, we would use the code given next:
$data = array(
‘username’ => ‘joebloggs’,
’email’ => ‘email@example.com’,
‘logged_in’ => TRUE
To retrieve session data we use: $this->session->userdata(‘username’);
8. How to unset and distroy session data.
To remove a single session item—the username, for example—we would use the following function:
To destroy a session completely, we would use the following function:
Chapter 3:Form validation and database interaction
- Why should we need to validate form? How to load the form validation library?
Ans: We should need to validate form for following reason:
- Prevent stored any information directly in a database.
- We can limit the types of data being allowed in our forms.
- Makes easy to re-populate our form fields.
- To show individual errors for each field.
- Making the overall end user experience better.
- To stop people abusing our form.
To load the form validation library. we can do this in one line, by passing an array to the load->library function.
2. List some form validation rules.
Ans. The following rules are readily available for use:
- What is callback function? How to call callback function in CI.
Ans. A callback is simply a function in our Controller code that is used in place, or along with, a rule.
We add callback function like following:
$this->form_validation->set_rules(’email’, ‘Email Address’,
The rule callback_add_user—will run the e-mail through the function add_user() in our controller.
Chapter 4: User authentication:
- How to use anchor in codeigniter?
Ans: Anchor creates a standard HTML anchor link based on our local site URL:
<a href=”http://example.com”>Click Here</a>
The tag has three optional parameters:
anchor(uri segments, text, attributes)
The first parameter can contain any segments we wish appended to the URL.
Chapter 6: Application Security
- What is URI? How to get URI link in CI?
Ans: A URI means Uniform Resource Identifier. it is everything that comes after our web address.When using CodeIgniter, we will have a URI that looks like this:
We can get the URI string by using PHP quite simply as follows:
$uri = $_SERVER[‘REQUEST_URI’];
2. Discuss the URI ‘index.php/controller/method/parameters’?
Ans: Everything after the index.php segment is used by CodeIgniter to determine what to load. The first segment is the name of the Controller. The second segment is used to determine which function to load—if this is blank then the index function will be used. The final segment parameters will be used to pass any data to the function.
3. What’s the difference between URI and QUERY String in codeigniter.
URI Strings :URI Strings are more search engine friendly and also more readable for our site’s visitors
QueryString: Query String is a older based style that is not easy to read and nor user friendly.
- Why does codeigniter restrict URI characters?
Ans:There are a few reasons as to why CodeIgniter restricts:
To avoid asterisk (*) or quotations—either single quotes or double quotes.
sanitize all parameters that are passed to all functions where we accept them.
The controller and model segments that are not allowed in a PHP class name or function name.
- What is hash? Name two popular hashing algorithm?
Ans: Hashing is a strong security way to store a user password. Like encoding, hashing values cannot be decoded.
Two popular hashing algorithm:MD5 and Sha1
- What is salting?
The salting is a process of adding a string with a password to change its end hash, which will be completely different from the original password hash.
$salt = ‘123456789987654321’;
$password = ‘password’;
$hash = sha1($salt . $password);
- Discuss query building?
Ans:Query binding allows we to write a query and bind certain values to it for later use.
8. What is Cross-site scripting?
Chapter 8: Web Services
1. What is web service?
And: “a software system designed to support interoperable machine-to-machine interaction over a network”.For example: RSS
- What is RPC?
Ans: Means Remote Procedure Call. It’s a web service that provide a set of functions that interface to the application directly. XML-RPC is a specification and a set of implementations that allows software to communicate with a server by using the XML as the request.
- What is RESTful web service?
Ans: REST means Representational State Transfer. REST is a method which, rather than defining functions that can be used in applications, defines a resource—a URI—to be used to perform actions on. In CI, web service can be developed using REST.