Introduction To Code Igniter

  • 12,847 views
Uploaded on

Lecture on CodeIgniter, # OSS Essential Training Program at Chittagong University of Engineering Technology, February 2008, http://bdosdn.org/wsatcuet.php

Lecture on CodeIgniter, # OSS Essential Training Program at Chittagong University of Engineering Technology, February 2008, http://bdosdn.org/wsatcuet.php

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
12,847
On Slideshare
0
From Embeds
0
Number of Embeds
3

Actions

Shares
Downloads
926
Comments
0
Likes
15

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Introduction To CodeIgniter Mohammad Amzad Hossain Softwork Solutions [email_address]
  • 2. Prerequisite
    • OOP – Object Oriented Programming
    • PHP
    • MySQL
  • 3. Index
    • Introduction
      • Evolution Of Web Development
      • Basic Idea Of Web Framework
      • Why Framework not Scratch?
      • MVC ( Model View Controller) Architecture
      • What is CodeIgniter ????
    • Installation of CodeIgniter
    • Application Flow of CodeIgniter
      • CodeIgniter URL
      • Controllers
      • Views
      • Models
      • CodeIgniter Libraries
      • Helpers
    • A Basic Application Development Of Codeigniter
      • Application Flow
    • Q/A
    • Reference
  • 4. Evolution of Web Development How you first started building websites.
  • 5. Evolution of Web Development How you’re building websites now.
  • 6. Evolution of Web Development How you build websites with a framework
  • 7. Basic Idea Of Web Framework
    • A web application framework
      • Is a Software framework
      • Designed to support the development of
        • Dynamic websites
        • Web applications
        • Web services
      • Aims to alleviate the overhead associated with common activities used in Web development.
        • Libraries for database access
        • Templating frameworks
        • Session management
        • Often promote code reuse
        • Many more …….
  • 8. Why Framework Not Scratch ?
    • Key Factors of a Development
      • Interface Design
      • Business Logic
      • Database Manipulation
      • User Access Control
    • Advantage of Framework
      • Templating
      • Provide Solutions to Common problems
      • Abstract Levels of functionality
      • Make Rapid Development Easier
    • Disadvantage of Scratch Development
      • Make your own Abstract Layer
      • Solve Common Problems Yourself
      • The more Typing Speed the more faster
  • 9. MVC Architecture
    • Separates User Interface From Business Logic
    • Model - Encapsulates core application data and functionality Business Logic.
    • View - obtains data from the model and presents it to the user.
    • Controller - receives and translates input to requests on the model or the view
    Figure : 01
  • 10. What is CodeIgniter ???
    • An Open Source Web Application Framework
    • Nearly Zero Configuration
    • MVC ( Model View Controller ) Architecture
    • Multiple DB (Database) support
    • DB Objects
    • Templating
    • Caching
    • Modules
    • Validation
    • Rich Sets of Libraries for Commonly Needed Tasks
    • Has a Clear, Thorough documentation
  • 11. Installation of CodeIgniter
    • Requirments
      • Web Server - Download & Install Apache
      • PHP – 4.3.2 or Higher
      • Database – MySQL ( support for other DB exists )
    • Installation
      • Download the latest version from www.codeigniter.com and unzip into your web root directory.
      • Open “application/config/config.php” and change base_url value to base url. For example: http://localhost/myci/
      • To Use Database open “application/config/database.php” and change necessary values. Usually you have to change: ‘hostname’, ‘username’, ‘password’, ‘datbase’.
      • Start Your Web Server and Database Server and go to http:// localhot/myci
  • 12. Application Flow Of CodeIgniter Figure : 2 [ Application Flow of CodeIgniter]
  • 13. CodeIgniter URL
    • URL in CodeIgniter is Segment Based.
    Segments in a URI CodeIgniter Optionally Supports Query String URL www.your-site.com/ news / article / my_article www.your-site.com/ class / function / ID www.your-site.com/index.php? c=news & m=article & ID=345
  • 14. Controllers
    • A Class file resides under “application/controllers”
    www.your-site.com/index.php/ first <?php class First extends Controller{ function First() { parent::Controller(); } function index () { echo “<h1> Hello CUET !! </h1> “; } } ?> // Output Will be “Hello CUET!!”
    • Note:
      • Class names must start with an Uppercase Letter.
      • In case of “constructor” you must use “parent::Controller();”
  • 15. Controllers
    • In This Particular Code
    <?php class First extends Controller{ function index() { echo “<h1> Hello CUET !! </h1> “; } function bdosdn ( $location ) { echo “<h2> Hello $location !! </h2>”; } } ?> // Output Will be “Hello world !!” www.your-site.com/index.php/ first / bdosdn/ world
    • Note:
      • The ‘Index’ Function always loads by default. Unless there is a second segment in the URL
  • 16. VIEWS
    • A Webpage or A page Fragment
    • Should be placed under “application/views”
    • Never Called Directly
    <html> <title> My First CodeIgniter Project</title> <body> <h1> Welcome ALL … To My .. ::: First Project ::: . . . </h1> </body> </html> web_root/myci/system/application/views/myview.php
  • 17. VIEWS
    • Calling a VIEW from Controller
    Data Passing to a VIEW from Controller $this->load->view(‘myview’); function index() { $var = array( ‘ full_name’ => ‘Amzad Hossain’, ‘ email’ => ‘tohi1000@yahoo.com’ ); $this->load->view(‘myview’, $var); } <html> <title> ..::Personal Info::.. </title> <body> Full Name : <?php echo $full_name;?> <br /> E-mail : <?=email;?> <br /> </body> </html>
  • 18. VIEWS
    • There are 3 mechanism that can be utilize to show Dynamic Data inside a VIEW File
    • - Pure PHP
    • - PHP’s Alternative Syntax
    • - CodeIgniter’s Template Engine
    <!-- PHP’s Alternative Syntax --> <?php if( $for_this == true ):?> <h1> For This </h1> <?php elseif( $for_that == true ): ?> <h1> For That </h1> <?php else: ?> <h1> What </h1> <?php endif; ?>
    • Note:
      • There are other alternative syntax ‘for’, ‘foreach’, ‘while’
  • 19. Models
    • Designed to work with Information of Database
    • Models Should be placed Under “application/models/”
    Loading a Model inside a Controller <?php class Mymodel extend Model{ function Mymodel() { parent::Model(); } function get_info () { $query = $this->db->get(‘name’, 10); /*Using ActiveRecord*/ return $query->result(); } } ?> $this->load->model(‘mymodel’); $data = $this->mymodel->get_info();
  • 20. CodeIgniter Libraries Special Purpose Classes Loading CodeIgniter Library Benchmarking Database Encryption Calendaring FTP Table File Uploading Email Image Manipulation Pagination Input and Security HTML Trackback Parser Session Template Unit Testing User Agent URI Validation $this->load->library(‘database’);
  • 21. CodeIgniter Libraries
    • Database Library
    • Abstract Database Class support traditional structures and Active Record Pattern.
    Active Record Pattern General Approach function index() { $this->load->library(‘database’); $rslt = $this->db->query (“ select first_name from user_name ”); foreach( $rslt->result() as $row_data) echo $row_data->first_name . “<br />”; } function index() { $this->load->library(‘database’); $this->db->select(“first_name”); $rslt = $this->db->get (“ user_name ”); foreach( $rslt->result() as $row_data) echo $row_data->first_name . “<br />”; }
  • 22. Helpers
    • Simply a collection of functions in a particular category.
    Loading A Helper Inside a Controller Array Date File HTML Smiley Text URL Cookie Download Form Security String Directory E-mail Inflector XML Parser Typography $this->load->helper(‘helper_name’); $this->load->helper(array(‘form’,’url’) );
  • 23. Helpers
    • Form Helper
      • form_open()
      • form_open_multipart()
      • form_input()
      • form_textarea()
      • form_checkbox()
      • form_submit()
      • form_close()
    • URL Helper
      • site_url()
      • base_url()
      • anchor()
      • anchor_popup()
      • mailto()
  • 24. A Personal Blog Using CI
  • 25. Questions & Answers
  • 26. Useful Links
    • www.codeigniter.com
    • http://codeigniter.com/wiki/Summary_of_Resources_Libraries_Helpers_Plugins.../
  • 27. Reference
    • User Guide of CodeIgniter 1.6.1
    • Wikipedia
    • PHPit
    • Slideshare