43146542 Codeigniter Intro

download 43146542 Codeigniter Intro

of 25

Transcript of 43146542 Codeigniter Intro

  • 8/8/2019 43146542 Codeigniter Intro

    1/25

    Introduction ToIntroduction ToCodeIgniterCodeIgniter

  • 8/8/2019 43146542 Codeigniter Intro

    2/25

    PrerequisitePrerequisite

    OOP Object OrientedProgrammingPHPMySQL

  • 8/8/2019 43146542 Codeigniter Intro

    3/25

    IndexIndexIntroduction

    Evolution Of Web DevelopmentBasic Idea Of Web FrameworkWhy Framework not Scratch?MVC ( Model View Controller) ArchitectureWhat is CodeIgniter ????

    Installation of CodeIgniterApplication Flow of CodeIgniterCodeIgniter URLControllersViewsModels

    CodeIgniter LibrariesHelpers

    A Basic Application Development Of CodeigniterApplication Flow

    Q/AReference

  • 8/8/2019 43146542 Codeigniter Intro

    4/25

    Evolution of WebEvolution of WebDevelopmentDevelopment

    How you first started buildingHow you first started buildingwebsites.websites.

  • 8/8/2019 43146542 Codeigniter Intro

    5/25

    Evolution of WebEvolution of WebDevelopmentDevelopment

    How youre building websitesHow youre building websitesnow.now.

  • 8/8/2019 43146542 Codeigniter Intro

    6/25

    Evolution of WebEvolution of WebDevelopmentDevelopment

    How you build websites with aHow you build websites with aframeworkframework

  • 8/8/2019 43146542 Codeigniter Intro

    7/25

    Basic Idea Of WebBasic Idea Of WebFrameworkFrameworkA web application framework

    Is a Software frameworkDesigned to support the development of

    Dynamic websitesWeb applicationsWeb services

    Aims to alleviate the overhead associated with common activities usedin Web development.

    Libraries for database accessTemplating frameworksSession managementOften promote code reuseMany more .

  • 8/8/2019 43146542 Codeigniter Intro

    8/25

    Why Framework NotWhy Framework NotScratch ?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

  • 8/8/2019 43146542 Codeigniter Intro

    9/25

    MVC ArchitectureMVC ArchitectureSeparates User Interface From Business LogicModel - Encapsulates core application data and functionality BusinessLogic.View - obtains data from the model and presents it to the user.Controller - receives and translates input to requests on the model orthe view

    Figure : 01

  • 8/8/2019 43146542 Codeigniter Intro

    10/25

    What is CodeIgniter ???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

  • 8/8/2019 43146542 Codeigniter Intro

    11/25

    Installation of CodeIgniterInstallation of CodeIgniterRequirments

    Web Server - Download & Install ApachePHP 4.3.2 or HigherDatabase MySQL ( support for other DB exists )

    InstallationDownload the latest version from www.codeigniter.com and unzip into your webroot directory.Open application/config/config.php and change base_url value to base url. Forexample: 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

    http://www.codeigniter.com/http://localhot/mycihttp://localhot/mycihttp://www.codeigniter.com/
  • 8/8/2019 43146542 Codeigniter Intro

    12/25

    Application Flow Of Application Flow Of CodeIgniterCodeIgniter

    Figure : 2 [ Application Flow of CodeIgniter]

  • 8/8/2019 43146542 Codeigniter Intro

    13/25

    CodeIgniter URLCodeIgniter URLURL in CodeIgniter is Segment Based.www.your-site.com/ news /article /my_article

    Segments in a URI

    www.your-site.com/ class /function /ID

    CodeIgniter Optionally Supports Query String URL

    www.your-site.com/index.php? c=news &m=article &ID=345

  • 8/8/2019 43146542 Codeigniter Intro

    14/25

    ControllersControllersA Class file resides under application/controllerswww.your-site.com/index.php/ first

    // Output Will be Hello CUET!!

    Note: Class names must start with an Uppercase Letter.

    In case of constructor you must use parent::Controller();

  • 8/8/2019 43146542 Codeigniter Intro

    15/25

    ControllersControllersIn This Particular Code

    // 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 secondsegment in the URL

  • 8/8/2019 43146542 Codeigniter Intro

    16/25

    VIEWSVIEWSA Webpage or A page FragmentShould be placed under application/viewsNever Called Directly

    My First CodeIgniter Project

    Welcome ALL To My .. ::: First Project ::: .

    . .

    web_root/myci/system/application/views/myview.php

    16

  • 8/8/2019 43146542 Codeigniter Intro

    17/25

    VIEWSVIEWSCalling a VIEW from Controller

    $this->load->view(myview);

    Data Passing to a VIEW from Controller

    function index() {

    $var = array(full_name => Amzad Hossain,email => [email protected]

    );$this->load->view(myview, $var);

    }

    ..::Personal Info::..

    Full Name :
    E-mail :

  • 8/8/2019 43146542 Codeigniter Intro

    18/25

    VIEWSVIEWSThere are 3 mechanism that can be utilize to show Dynamic Data inside aVIEW File

    - Pure PHP- PHPs Alternative Syntax- CodeIgniters Template Engine

    For This

    For That

    What

    Note: There are other alternative syntax for, foreach, while

  • 8/8/2019 43146542 Codeigniter Intro

    19/25

    ModelsModelsDesigned to work with Information of DatabaseModels Should be placed Under application/models/

    Loading a Model inside a Controller

    $this->load->model(mymodel);$data = $this->mymodel->get_info();

  • 8/8/2019 43146542 Codeigniter Intro

    20/25

    CodeIgniter LibrariesCodeIgniter Libraries

    Benchmarking Database Encryption Calendaring

    FTP Table File Uploading Email

    Image Manipulation Pagination Input and Security HTML

    Trackback Parser Session TemplateUnit Testing User Agent URI Validation

    Special Purpose Classes

    $this->load->library(database);

    Loading CodeIgniter Library

  • 8/8/2019 43146542 Codeigniter Intro

    21/25

    CodeIgniter LibrariesCodeIgniter LibrariesDatabase LibraryAbstract Database Class support traditional structures and Active Record Pattern.

    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 .
    ;

    }

    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 .
    ;

    }

    Active Record Pattern

    General Approach

  • 8/8/2019 43146542 Codeigniter Intro

    22/25

    HelpersHelpersSimply a collection of functions in a particular category.

    Array Date File HTML Smiley Text

    URL Cookie Download Form Security String

    Directory E-mail Inflector XML Parser Typography

    $this->load->helper(helper_name);

    Loading A Helper Inside a Controller

    $this->load->helper(array(form,url) );

  • 8/8/2019 43146542 Codeigniter Intro

    23/25

    HelpersHelpersForm Helper

    form_open()form_open_multipart()form_input()form_textarea()form_checkbox()form_submit()form_close()

    URL Helpersite_url()base_url()

    anchor()anchor_popup()mailto()

  • 8/8/2019 43146542 Codeigniter Intro

    24/25

    A Personal Blog Using CIA Personal Blog Using CI

  • 8/8/2019 43146542 Codeigniter Intro

    25/25

    Questions???Questions???