introduction to code igniter
TRANSCRIPT
![Page 1: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/1.jpg)
Introduction To Introduction To CodeIgniterCodeIgniter
Mohammad Amzad HossainSoftwork [email protected]
![Page 2: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/2.jpg)
PrerequisitePrerequisite
OOP – Object Oriented Programming
PHPMySQL
![Page 3: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/3.jpg)
IndexIndex 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
![Page 4: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/4.jpg)
Evolution of Web Evolution of Web DevelopmentDevelopment
How you first started building How you first started building websites.websites.
![Page 5: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/5.jpg)
Evolution of Web Evolution of Web DevelopmentDevelopment
How you’re building websites How you’re building websites now.now.
![Page 6: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/6.jpg)
Evolution of Web Evolution of Web DevelopmentDevelopment
How you build websites with a How you build websites with a frameworkframework
![Page 7: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/7.jpg)
Basic Idea Of Web Basic Idea Of Web FrameworkFrameworkA 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 …….
![Page 8: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/8.jpg)
Why Framework Not Why Framework Not Scratch ? 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
![Page 9: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/9.jpg)
MVC ArchitectureMVC 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
![Page 10: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/10.jpg)
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
![Page 11: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/11.jpg)
Installation of CodeIgniterInstallation 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
![Page 12: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/12.jpg)
Application Flow Of Application Flow Of CodeIgniterCodeIgniter
Figure : 2 [ Application Flow of CodeIgniter]
![Page 13: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/13.jpg)
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
![Page 14: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/14.jpg)
ControllersControllersA 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();”
![Page 15: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/15.jpg)
ControllersControllersIn 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
![Page 16: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/16.jpg)
VIEWSVIEWS 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
16
![Page 17: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/17.jpg)
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);
}
<html><title> ..::Personal Info::.. </title><body>Full Name : <?php echo $full_name;?> <br />E-mail : <?=email;?> <br /></body></html>
![Page 18: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/18.jpg)
VIEWSVIEWSThere 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’
![Page 19: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/19.jpg)
ModelsModelsDesigned to work with Information of Database
Models Should be placed Under “application/models/”
<?php
class Mymodel extend Model{function Mymodel() {
parent::Model();}function get_info() {
$query = $this->db->get(‘name’, 10); /*Using ActiveRecord*/return $query->result();
}}?>
Loading a Model inside a Controller
$this->load->model(‘mymodel’);$data = $this->mymodel->get_info();
![Page 20: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/20.jpg)
CodeIgniter LibrariesCodeIgniter Libraries
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
Special Purpose Classes
$this->load->library(‘database’);
Loading CodeIgniter Library
![Page 21: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/21.jpg)
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 . “<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 />”;
}
Active Record Pattern
General Approach
![Page 22: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/22.jpg)
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’) );
![Page 23: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/23.jpg)
HelpersHelpersForm 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()
![Page 24: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/24.jpg)
A Personal Blog Using CIA Personal Blog Using CI
![Page 25: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/25.jpg)
Questions & Questions & AnswersAnswers
![Page 26: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/26.jpg)
Useful Links www.codeigniter.com http://codeigniter.com/wiki/Summary_of_Resources_Li
braries_Helpers_Plugins.../
![Page 27: Introduction To Code Igniter](https://reader033.vdocuments.mx/reader033/viewer/2022061518/55d4d474bb61ebe5488b45f5/html5/thumbnails/27.jpg)
ReferenceReference User Guide of CodeIgniter 1.6.1 Wikipedia PHPit Slideshare