Loading...
Flash Player 9 (or above) is needed to view slideshows. We have detected that you do not have it on your computer.To install it, go here
Introduction To CodeIgniter
Introduction to CodeIgniter presentation given at Refresh OKC on 17 Jun 2008.
965 views | comments | 0 favorites | 23 downloads | 0 embeds (Stats)
More Info
This slideshow is Public
Total Views: 965 on Slideshare: 965 from embeds: 0
Slideshow Transcript
- Slide 1: Introduction to
CodeIgniter
Steve Webb
Refresh OKC
17 Jun 2008
- Slide 2: What is CodeIgniter?
CodeIgniter is a lightweight web
application framework written in PHP that
adopts the model-view-controller
approach to development
- Slide 3: Why use a framework?
Web application frameworks provide basic
building blocks needed by most
applications
– Database connections
– Business logic
– Form handling
Separation of concerns
Easier testing (unit tests)
- Slide 4: Why use CodeIgniter?
Feature rich
Lightweight
Open source
Well-supported by an active community
Excellent “by example” documentation
Easy to configure
Supports multiple databases
- Slide 5: Why use CodeIgniter?
In short, CodeIgniter is nice because it
does what it needs to do and then gets
out of the way.
- Slide 6: Model-View-Controller
Model – representation of the data
View – rendering of the data suitable for
interaction with the user
Controller – the “traffic cop” that passes
model data to the views and vice versa
This separation of concerns allows for
greater flexibility, reuse of code, and
overall preservation of the developer’s
sanity
- Slide 7: Controller
A class containing one or more related methods
(custom PHP functions)
Typical uses:
– Request a set of data from the model by sending
arguments
– Send a payload of data to a view (web page)
– Receive a data payload from a view
– Apply business logic to make decisions
– Pass data to the model for inclusion in a database
- Slide 8: View
Code that displays information to the user
Views can be:
– Web pages with PHP code snippets inserted
– Web pages with forms to gather user input
– Other output (CSV, PDF, etc.)
- Slide 9: Model
A class containing one or more related
methods (custom PHP functions)
Typical uses:
– Create
– Read
– Update
– Delete
- Slide 10: CodeIgniter Classes
CI’s built-in classes contain the basic
functionality that are frequently used by
web applications
The most-used classes are:
– Database
– Input
– Loader
– URI
– Validation
- Slide 11: Database Class
Generates queries using the Active Record
Pattern
Automatic escaping of input values
Provides method “chaining” for easy query
building
$this->db->where(‘name’,$name);
- Slide 12: Input Class
Pre-processes user input (prevents common
cross-site scripting techniques)
Provides access to user input and other data:
– Form fields (POST)
– Cookies
– Server variables
$this->input->post(‘fieldname’);
- Slide 13: Loader Class
Makes various resources available:
– Databases
– Views
– Helpers
– Plugins
$this->load->view(‘viewname’);
- Slide 14: URI Class
Provides access to specific parts of the
URI string
Useful for building RESTful URIs
$this->uri->segment(n);
- Slide 15: Validation Class
Helps validate user form input
– Required fields
– Required string formatting (length, regexp)
Enables success and failure messages on
form submittal
Enables re-population of form fields after
form submittal
- Slide 16: Other Classes
Benchmarking Language
Calendaring (internationalization)
Email Output
Encryption Pagination
File uploading Session
FTP Trackback
HTML Table Unit testing
Image Manipulation XML-RPC
Zip encoding
- Slide 17: Helpers and Plugins
CodeIgniter comes with a wide array of
“helper” functions that add convenience to
applications and provide ease of reuse.
$this->load->helper(‘helper_name’);
CodeIgniter also allows for the use of
custom add-on functions called “plugins”.
$this->load->plugin(‘plugin_name’);
- Slide 18: My First CI Application
1. Unzip CI zip file into application folder on web
server
2. [optional] For “pretty URLs”, add .htaccess file
and enable mod_rewrite in Apache
3. Configure database in CI’s <config.php>
4. Write controller (or modify existing)
5. Write view (or modify existing)
6. Write model
- Slide 19: Demo