Codeigniter interview questions and answers

Similar documents
Configuration Setting

Let's have a look at the normal Joomla! URLs:

System Guide

Get in Touch Module 1 - Core PHP XHTML

STS v4.2 with HTC v2.5.9

Siteforce Pilot: Best Practices

TUTORIAL MADCAP FLARE Top Navigation

Ruby on Rails Welcome. Using the exercise files

StockStatusMonitoring_Technical Documentation

WP EBOOKS Creating A WordPress Network

Step 1: Upload a video (skip to Step 2 if you ve already uploaded a video directly from your ipod, Uploading to YouTube and Posting in Blackboard

Case Study Schedule. NoSQL/NewSQL Database Distributed File System Peer-to-peer (P2P) computing Cloud computing Big Data Internet of Thing

Roxen Content Provider

A Quick Introduction to the Genesis Framework for WordPress. How to Install the Genesis Framework (and a Child Theme)

Helpline No WhatsApp No.:

Creating a Network. WordPress 3.1 (and up)

Download, Install and Use Winzip

CSCI 4000 Assignment 5

Folders and Files. Folder

FAQ: Crawling, indexing & ranking(google Webmaster Help)

Manual Html Image Src Url Path Not Working

Wikispaces in Education A Comprehensive Tutorial

BEGINNER PHP Table of Contents

Master Syndication Gateway V2. User's Manual. Copyright Bontrager Connection LLC

I completely understand your anxiety when starting learn codeigniter.

Università degli Studi di Parma. Basi di Dati e Web. Introduction to CodeIgniter 14/01/2014. Basi di Dati e Web. martedì 14 gennaio 14

Blackboard course design

Sitelok Manual. Copyright Vibralogix. All rights reserved.

Class #7 Guidebook Page Expansion. By Ryan Stevenson

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Laravel

Hello everyone! Page 1. Your folder should look like this. To start with Run your XAMPP app and start your Apache and MySQL.

Advanced Online Media Dr. Cindy Royal Texas State University - San Marcos School of Journalism and Mass Communication

Contents 1. How can I import my users from another platform? How can I Create Membership Levels and Subscription Packs?

The connection has timed out

The CartIt Commerce System Installation Guide

Content Management Systems

Websites. Version 1.7

ultimo theme User Guide Extremely customizable Magento theme by Infortis Copyright Infortis All rights reserved

by D2L CONTENT DISCUSSIONS STUDENT CHANGES August, 2015 New Name, Same System!

Moodle Morsels from Sandy & Inkie. b. Click (Log in) on the upper right c. You will use your stpsb login, which is how you login to a computer

Developing Online Databases and Serving Biological Research Data

The Crypt Keeper Cemetery Software Online Version Tutorials To print this information, right-click on the contents and choose the 'Print' option.

Build Site Create your site

Mobile Site Development

FORMS. The Exciting World of Creating RSVPs and Gathering Information with Forms in ClickDimensions. Presented by: John Reamer

c122jan2714.notebook January 27, 2014

PHP WITH ANGULAR CURRICULUM. What you will Be Able to Achieve During This Course

WebLink Manual EZ-CAMP2

USER GUIDE MADCAP FLARE Topics

Kentico CMS Web Parts

Unable To Access An Error Message. Corresponding To Your Field Name. Codeigniter >>>CLICK HERE<<<

XAMPP Web Development Stack

Saurus CMS Installation Guide

Dreamweaver CS6. Table of Contents. Setting up a site in Dreamweaver! 2. Templates! 3. Using a Template! 3. Save the template! 4. Views!

How to create a secure WordPress install v1.1

Things to note: Each week Xampp will need to be installed. Xampp is Windows software, similar software is available for Mac, called Mamp.

Quick Start Manual for Mechanical TA

Senior Technical Specialist, IBM. Charles Price (Primary) Advisory Software Engineer, IBM. Matthias Falkenberg DX Development Team Lead, IBM

Webform: THERE IS THIS FOR THAT

Developing Online Databases and Serving Biological Research Data

FIREFOX MENU REFERENCE This menu reference is available in a prettier format at

My Favorite bash Tips and Tricks

Digication eportfolio Student s Guide (Last update: 8/2017)

Managing Your Website with Convert Community. My MU Health and My MU Health Nursing

End-User Reference Guide Troy University OU Campus Version 10

Http Error Code 403 Forbidden Dreamweaver Mysql

SilverStripe - Website content editors.

Client Configuration Cookbook

OU EDUCATE TRAINING MANUAL

Bluehost and WordPress

XCloner. Official User Manual. Copyright 2010 JoomlaPlug.com All rights reserved.

Working with the Seagull Framework. By Demian Turner, Seagull Systems

PHP. MIT 6.470, IAP 2010 Yafim Landa

How to Create an e-book. A Step-by-Step Illustrated Guide

How To Change My Wordpress Database

SmartList Senior Project Paper

& ( ); INSERT INTO ( ) SELECT

DevShala Technologies A-51, Sector 64 Noida, Uttar Pradesh PIN Contact us

AccessMail Users Manual for NJMLS members Rev 6

SEO TOOLBOX ADMINISTRATOR'S MANUAL :55. Administrator's Manual COPYRIGHT 2018 DECERNO AB 1 (13)

Vector Issue Tracker and License Manager - Administrator s Guide. Configuring and Maintaining Vector Issue Tracker and License Manager

How to Create a NetBeans PHP Project

USER MANUAL. Fooman Speedster (Magento 1) User Manual Quick Links. 1. Installation 2. Set up in Magento 3. Verification Steps 4.

Create-A-Page Design Documentation

Webform: THERE IS THIS FOR THAT

[PACKT] open source^ Kohana 3.0. Beginner's Guide. Develop professional web applications with Kohana. Jason D. Straughan

BF Survey Pro User Guide

Client Side JavaScript and AJAX

MEMBERSHIP & PARTICIPATION

Contains Errors Codeigniter

PHPRad. PHPRad At a Glance. This tutorial will show you basic functionalities in PHPRad and

e-portfolios Benefits of an e-portfolio Showcase your best works Progress assessment Job search; present to employers Share with family and friends

CS Homework 12

Webshop Plus! v Pablo Software Solutions DB Technosystems

Tutorials Php Y Jquery Mysql Database Without Refreshing Code

PHP for PL/SQL Developers. Lewis Cunningham JP Morgan Chase

These five steps are necessary for a successful upgrade. Please pay close attention to any of them, and do not skip any steps.

Creating a Course Web Site

BreezingForms Custom Fields for VirtueMart 2

Creating Pages with the CivicPlus System

Transcription:

Codeigniter interview questions and answers For freshers and experienced Content Ref :pcds.co.in only for use Education and Job purpose, not for official purpose. : 1 1 What is codeigniter? Codeigniter is a framework which is mainly focussed on web application development.it is well known for its performance speed.it has inbuilt libraries which helps to build web application : 2 2 Who developed codeigniter? Codeigniter was developed bt ellislab Inc. : 3 3 Why codeigniter is called as loosely based mvc framework? advertisements Reason behind this is we does not need to follow strict mvc pattern while creating application.we can also able to build with model only view and controllers are enough to built a application. : 4 4 What are helpers? It is a group of functions which helps you to do particular functions. Example there are form helper to create a form.$this->load->helper( form ); : 5 5 What are hooks in codeigniter? Hooks are used to modify the inner functionality of framework without affecting core files.hooks are present in application/config/hooks.php : 6 6 How to insert data into database table in CodeIgniter? Step1 This will be your controller. <?php class Site extends CI_Controller function index() $this->load->view( form.php );// loading form view function insert() 1

$this->load->model( site_model ); $this->site_model->insert(); $this->load->view( success.php );//loading success view Step 2 This will be your views. Befor creating views go to autoload.php and autoload url helper and database class. In your config.php set config['base_url'] = path to your site ; form.php <form action= <?php echo base_url();?>site/insert method= post > Field 1 <input type = text name= f1 ><br> Field 2 <input type = text name= f2 ><br> Field 3 <input type = text name= f3 ><br> <input type= submit > </form> Step 3 success.php <b>your data has been inserted!!!</b> Step 4 In your model you need to pull those datas of form and insert into db this way site_model.php <?php class Site_model extends CI_Model function insert() $f1 = $_POST['f1']; $f2 = $_POST['f2']; $f3 = $_POST['f3']; $this->db->query( INSERT INTO tbl_name VALUES( $f1, $f2, $f3 ) ); There must be some problem with your configuration. To use the process above please set the following settings. In your application/config/autoload.php => $autoload['libraries'] = array( database ); $autoload['helper'] = array( url ); If you have not used htaccess or route files then in URL place the full URL. : 7 7 How do I embed views within views? Nested templates? Header, Main, Footer (Blocks) design? Partials? Page Fragments? Ruby on Rails style Yield functionality? There are several other described ways to deal with this problem: Version 1.6 (Released January 31, 2008) has support for multiple views. See the User Guide for more 2

details. That change to the core makes some of these approaches "old school" (as it were). This forum thread covers some good ground: http://codeigniter.com/forums/viewthread/87346/ First, basic information on views and the optional third 'return' parameter: http://www.codeigniter.com/wiki/displaying_multiple_views/ and also, The CI Loader class documentation page Coolfactor's View Library is one solution to nesting views in a tidy way. http://codeigniter.com/forums/viewthread/49910/ Gyorgy Fekete's View library similar to Coolfactor's with the differences spelled out in the thread. http://codeigniter.com/forums/viewthread/62521/ Another place to get advice if you don't want to add a new library is Rick Ellis' original thread on the subject (Embedding Views within Views). http://codeigniter.com/forums/viewthread/44916/ Also, teamhurting has implemented a Ruby On Rails style Yield approach that uses CI's hooks system: Yield using hooks - http://codeigniter.com/forums/viewthread/57902/ Another similar approach using a basic class rather than a class as a hook: http://codeigniter.com/wiki/layout_library/ A thread where esra lists a few threads on this topic: http://codeigniter.com/forums/viewthread/57965/ A Rails-Style ActionView library and helper called Ocular has a web page wiki here: http://codeigniter.com/wiki/ocular_layout_library/ and a thread here: http://codeigniter.com/forums/viewthread/65050/ A thread for a View library (author tested with Matchbox) http://codeigniter.com/forums/viewthread/67028/ : 8 8 How to Preparing Database for CodeIgniter? Create a database named "codeigniter" and a table named "hello". We use phpmyadmin for easy. Open your phpmyadmin. Enter database name "codeigniter" in create new database field. Click Create button. Your database will be created. 3

Create new table by entering name of new table at create new table field. Enter number of fields. Click Go button. Enter name of field, type, and length Choose auto increment and check primary key for primary key field. Click Save button. Now, we insert data. Click Insert tab. Enter data. Click Go for saving. : 9 9 How do I pass parameters to a controller\'s index() function? The obvious problem is that a second parameter on the URL will be interpreted as the method name. Short answer - use a URL like this: /controller/index/param1/param2 Long answer- using _remap() you can work some magic. This code is supplied courtesy of Colin Williams function _remap ( $method ) $param_offset = 2; // Default to index if (! method_exists($this, $method)) // We need one more param $param_offset = 1; $method = 'index'; // Since all we get is $method, load up everything else in the URI $params = array_slice($this->uri->rsegment_array(), $param_offset); // Call the determined method with all params call_user_func_array(array($this, $method), $params); 4

: 10 10 : 11 11 How do I do a COUNT(\'foo\') using the Active Record functions? You need to use the SQL AS feature, where you assign a new name to a piece of data. For example: $this->db->select("count('foo') AS foo_count", FALSE); // Run your query How to Install CodeIgniter? CodeIgniter is installed in four steps: Unzip the package. Upload the CodeIgniter folders and files to your server. Normally the index.php file will be at your root Open the application/config/config.php file with a text editor and set your base URL. If you intend to use encryption or sessions, set your encryption key. If you intend to use a database, open the application/config/database.php file with a text editor and set your database settings. If you wish to increase security by hiding the location of your CodeIgniter files you can rename the system and application folders to something more private. If you do rename them, you must open your main index.php file and set the $system_folder and $application_folder variables at the top of the file with the new name you've chosen. For the best security, both the system and any application folders should be placed above web root so that they are not directly accessible via a browser. By default,.htaccess files are included in each folder to help prevent direct access, but it is best to remove them from public access entirely in case the web server configuration changes or doesn't abide by the.htaccess. After moving them, open your main index.php file and set the $system_folder and $application_folder variables, preferably with a full path, e.g. '/www/myuser/system'. One additional measure to take in production environments is to disable PHP error reporting and any other development-only functionality. In CodeIgniter, this can be done by setting the ENVIRONMENT constant, which is more fully described on the security page. That's it! If you're new to CodeIgniter, please read the Getting Started section of the User Guide to begin learning how to build dynamic PHP applications. Enjoy! If you wish to increase security by hiding the location of your CodeIgniter files you can rename the system and application folders to something more private. If you do rename them, you must open your main index.php file and set the $system_folder and $application_folder variables at the top of the file with the new name you've chosen. 5

For the best security, both the system and any application folders should be placed above web root so that they are not directly accessible via a browser. By default,.htaccess files are included in each folder to help prevent direct access, but it is best to remove them from public access entirely in case the web server configuration changes or doesn't abide by the.htaccess. After moving them, open your main index.php file and set the $system_folder and $application_folder variables, preferably with a full path, e.g. '/www/myuser/system'. One additional measure to take in production environments is to disable PHP error reporting and any other development-only functionality. In CodeIgniter, this can be done by setting the ENVIRONMENT constant, which is more fully described on the security page. That's it! If you're new to CodeIgniter, please read the Getting Started section of the User Guide to begin learning how to build dynamic PHP applications. Enjoy! : 12 12 How do I call one Controller\'s methods from a different Controller? Short answer: You don't Wrong answer: Use the $CI = get_instance() trick. Long answer: You shouldn't actually be trying to do this. It implies that your design isn't quite easy to re-engineer the relevant bits when you first discover this problem. It's likely that the method you want to call should simply be relocated - this might mean moving it into a helper, library, model or your MY_Controller - where it can be accessed by any number of controllers. : 13 13 Can I cache only certain parts of a page? This is related to the question above about nested templates and partials. Basically, CI cache library (1.5.4) only supports full page caching - it's all or nothing. There are several ontributions that can help. The Sparks library is one approach. (NOTE: the Sparks object caching library is currently an orphan (as of 20070925) as the developer has moved on to Zend Framework - anyone want to step up and carry it on?) In case you have questions to ask on the forum, please review this general information on caches. There are many levels of caching and they can be broken down into a few categories and approaches: PHP code itself: php opcode of some kind 6

The following can be classed as session-specific or global caches depending on the approach: DB cache: db query, db object serialization HTML output cache: partial or full page caching Browser cache is always (by definition) session-specific: Browser cache: using headers to control cache, JS and CSS architecture to optimize browser cache-ability : 14 14 Can I extend the core Database class? No, you can not. This is quite explicitly described in the Creating Libraries section of the user guide: [quote] The Database classes can not be extended or replaced with your own classes, nor can the Loader class in PHP 4. All other classes are able to be replaced/extended. [/quote] : 15 15 : 16 16 How do I call methods in one controller via another controller? Often this question disguises a requirement for some shared methods - consult the earlier question on **View Partials* and Header/Footer/Menu common views first, and confirm your question isn't better answered there How do I find out the ID of the row I just inserted? (Just so that people searching for this will be more likely to find it, we'll mention that this is comparable to the native PHP mysql_insert_id() function.) $foo = $this->db->insert_id(); : 17 17 How do I see the actual raw SQL query generated by CI\'s Active Record You can do this before your query: $this->db->_compile_select();.. and then this, once you've run the query: : 18 18 $this->db->last_query(); How to Create Application at CodeIgniter? First, we make controller, create a file name "hello.php" within: \system\application\controllers. Enter following code: Next step, make a view. Create you_view.php within CodeIgnitersystemapplicationviews. Enter just simple line code like: 1 Hello, you! 7

Now, test your application. Point your browser to http://localhost/codeigniter/index.php/hello/you You should get like this: : 19 19 How to Install CodeIgniter Framemwork CodeIgniter Step By Step Tutorial: After understand about codeigniter at this, now, we learn how to install CodeIgniter. We will install to our local computer. Before follow this instruction please download CodeIgniter at www.codeigniter.com. Open your root web server. Put CodeIgniter downloaded. Extract it, you will get a folder named "codeigniter_[version]". For simple, rename the folder to be "CodeIgniter" only. Now, open config.php within CodeIgnitersystemapplicationconfig. Change base site url at line 14: Point your browser to http://localhost/codeigniter. : 20 20 I keep repeating lumps of code - things like login-dialogs, stylesheets, headers, footers, or menus - is there some place I can define them just once? this is also covered by the next section (on nested templates, view partials etc) which in turn contains many links into the forums - this will provide a wealth of alternative approaches. It is also asked frequently (hence its presence here - duh!) on the forums -- about once every 36 hours on average, usually prefaced with the lie 'I couldn't find anything about how to do this...'. You're advised (read strongly encouraged) to use the forum search feature and Search in Titles Only for the words 'header' and 'footer : 21 21 Is there a way to cycle $this->input->post() items? There are no CodeIgniter functions to do this, but you can accomplish this easily with a construct such as this one. The result of this function is a $safe_post_array that contains all posted data that has passed your own Input Class rules. foreach (array_keys($_post) as $key) $safe_post_array[$key] = $this->input->post($key); 8

You can also do something neat like this, if you want to pull all the data out of $_POST into your own array, cleaning it as it comes across: $data['fields'] = xss_clean($_post); : 22 22 : 23 23 Tell me the Setting Database Configuration open database.php within CodeIgniter\system\application\config. Set config Make sure, it match with your database. How do I migrate my existing \'normal\' PHP site to CodeIgniter? Put the whole site in a subfolder of your root web folder, and use.htaccess to rewrite all requests to the subfolder (we named it â oldsiteâ but any name will do). Be wary of absolute file paths (do a find on the entire codebase to look for any file that uses the filesystem). Make sure everything works before you continue any further. Now setup your CI site in the root of the webfolder. Make sure the.htaccess still routes all traffic to the old site. Now overwrite the Router class with a MY_Router. Let CI check if there is a controller present which matches against the url (the way it normally does). If not, redirect to the oldsite folder. Remove the.htaccess rule that redirects all traffic to the old site. Now every request will go through the CI index.php. The Router Class will test if a controller exists for the requested url. (just like it would normally so you can user your routes in your config folder). If it wonâ t find one, normally CI would return a 404. Instead it now redirects the request to the old site. Now you can slowly migrate parts of the website. Since the CI controllers take precedent over the old website, you can slowly replace parts of the old websites, and add new features as you would a normal CI site. One word of caution. This will seriously impact any pagerank google has given to your website, since google doesnâ t like redirects. To counter this you can use your.htaccess to rewrite old urls to the â oldsiteâ subfolder, although the list could become quite large. : 24 24 9 Is CodeIgniter uses a functions and names in its operation? CodeIgniter uses a series of functions and names in its operation. Because of this, some names cannot be used by a developer. Following is a list of reserved names that cannot be used Controller names Since your controller classes will extend the main application controller you must be careful not to name your functions identically to the ones used by that class, otherwise

10 your local functions will override them. The following is a list of reserved names. Do not name your controller any of these: Controller CI_Base _ci_initialize Default index Functions is_really_writable() load_class() get_config() config_item() show_error() show_404() log_message() _exception_handler() get_instance() Variables $config $mimes $lang Constants ENVIRONMENT EXT FCPATH SELF BASEPATH APPPATH CI_VERSION FILE_READ_MODE FILE_WRITE_MODE DIR_READ_MODE DIR_WRITE_MODE FOPEN_READ FOPEN_READ_WRITE FOPEN_WRITE_CREATE_DESTRUCTIVE FOPEN_READ_WRITE_CREATE_DESTRUCTIVE FOPEN_WRITE_CREATE FOPEN_READ_WRITE_CREATE

FOPEN_WRITE_CREATE_STRICT FOPEN_READ_WRITE_CREATE_STRICT : 25 25 How do I call one Model\'s methods from a different Model? Short answer: You don't Long answer: You shouldn't actually be trying to do this. It implies that your design isn't quite right. (Your design may be right - I'm just saying that this mplies that it's not (also, if you have to ask this question, this also suggests you probably shouldn't be doing this.)) Consider moving things around such that MY_Model or a library or helper contains the functionality you're trying to utilise in this way. If you absolutely positively have to do this (and remember - you shouldn't) you can do the old $CI = get_instance() trick. Phil explains it in this thread but loosely it is simply this: $ci =& get_instance(); $ci->load->model('mymodel'); $ci->mymodel->mymethod(); 11