Introduction To CodeIgniter

15,350 views
15,037 views

Published on

Introduction to CodeIgniter presentation given at Refresh OKC on 17 Jun 2008.

Published in: Business, Technology
1 Comment
6 Likes
Statistics
Notes
  • the best slides for MVC user
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
15,350
On SlideShare
0
From Embeds
0
Number of Embeds
30
Actions
Shares
0
Downloads
887
Comments
1
Likes
6
Embeds 0
No embeds

No notes for slide

Introduction To CodeIgniter

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

×