SlideShare a Scribd company logo
CodeIgniter and MVC 
Enterprise class web application development 
Dienstag, 4. Mai 2010
Motivation 
• You have worked with PHP, for small sites this works very well. HTML files 
can be easily extended with dynamic content from the database, form 
processing, etc. 
• When sites grow, you might have realized that across multiple pages lots of 
code repetition occurs. This is a problem when you need to change certain 
parts of a page, that affects many or all pages. 
• Furthermore, its hard to introduce new developers to code someone else 
has written. It takes a long time to get familar with the code. 
Dienstag, 4. Mai 2010
Motivation 
• Enterprise class (big) web applications need structure, one HTML file per 
page with PHP code is not optimal => things get confusing, hard to work in 
teams, etc. 
• Web Application Frameworks provide such a structure wich introduce 
seperation of concern, etc. 
• Most common for Web application development are frameworks that are 
based on the Model-View-Controller design pattern 
• Motivation video for a MVC framework: 
http://www.youtube.com/watch?v=p5EIrSM8dCA 
Dienstag, 4. Mai 2010
Model-View-Controller 
• „Seperation of concerns“ of Logic and Presentation 
• Controller: Handles all incoming HTTP requests, passes data to the views 
• View: Renders the HTML output 
• Models: Encapsulate Business Logic, such as interaction with the database 
• For PHP we introduce CodeIgniter 
Dienstag, 4. Mai 2010
CodeIgniter 
• CodeIgniter is a PHP-based MVC framework that helps structure your code 
and make redundant tasks less tedious. 
• There are countless similar PHP frameworks, the most popular ones being 
CakePHP and symfony. Ruby on Rails is famous in the Ruby world. 
• CodeIgniter is very light weight. It doesn‘t force any convention but provides 
many commonly required features through a set of build in libraries. 
• CodeIgniter has a low learning curve and is one of the best documented PHP 
web frameworks. 
Dienstag, 4. Mai 2010
CodeIgniter: Features 
• Model-View-Controller Based System 
• Extremely Light Weight, does not force any convention 
• Full Featured database classes with support for several platforms, 
Active Record Database Support (ORM) 
• Custom Routing 
• Form and Data Validation 
• Security and XSS Filtering 
Dienstag, 4. Mai 2010
Application Flow Chart 
1. The index.php serves as the front controller, initializing the base resources needed 
to run CodeIgniter. 
2. The Router examines the HTTP request to determine what should be done with it. 
3. If a cache file exists, it is sent directly to the browser, bypassing the normal 
system execution. 
4. Security. Before the application controller is loaded, the HTTP request and any 
user submitted data is filtered for security. 
5. The Controller loads the model, core libraries, plugins, helpers, and any other 
resources needed to process the specific request. 
6. The finalized View is rendered then sent to the web browser to be seen. If caching 
is enabled, the view is cached first so that on subsequent requests it can be 
served. 
Dienstag, 4. Mai 2010
Getting Started 
• Directory Structure of CodeIgniter: 
• index.php - recieves all requests and routes 
to the right controllers classes and actions, 
parameters are included in the URL 
• /system - contains all CodeIgniter classes 
and libraries provided by the framework 
• /application - this is where your application 
code is located, including the model, view 
and controller classes 
Dienstag, 4. Mai 2010
Controllers 
• Take incoming HTTP requests 
and process them 
• Must be the same filename as 
the capitalized class name 
• Must extend the main 
Controller class of CodeIgniter 
• Each class function represents 
an controller action, which is 
redering a HTML page 
• „index“ is the default action 
Dienstag, 4. Mai 2010
Routing Requests 
• Per default CodeIgniter maps URL to 
controller actions: 
/index.php/controller/action 
• The default controller is „welcome“ 
and the default action is „index“. 
• Custom routing can be configured 
through: 
/application/config/routes.php 
Dienstag, 4. Mai 2010
Views 
• Are HTML pages or page fragments 
• Those are load and sent by the 
Controller to the Browser by the use 
of the following code in den Ctrl: 
$this->load->view(‘blog_view‘); 
• There is no application logic in the 
views, only display logic 
(to some degree) 
• <?= is short form for <?php echo 
Dienstag, 4. Mai 2010
Controller & View sample 
Dienstag, 4. Mai 2010
Helpers 
• Helper functions are located in 
/application/helpers/ 
• These are small PHP functions 
that provide shortcuts, to 
outsource often used code 
• For example formatting, text, 
url or form helpers 
• Needs to be loaded through: 
$this->load->helper(‘name‘); 
Loading a Helper 
$this->load->helper('name'); 
Using a Helper 
<?php echo anchor('blog/comments', 'Click Here');?> 
Auto-loading Helpers 
application/config/autoload.php 
Text Helper 
$this->load->helper('text'); 
word_limiter() 
$string = "Here is a nice text string 
consisting of eleven words."; 
$string = word_limiter($string, 4); 
// Returns: Here is a nice… 
Dienstag, 4. Mai 2010
Libraries 
• Libraries are similar to helpers 
• The also need to be loaded through: 
$this->load->library('classname'); 
• The difference is that they encapsulate more 
complex functionality, such as image processing, 
form validation handling, caching, etc. 
• Libraries allow to dynamically extend 
CodeIgniters functionality and extendability 
Dienstag, 4. Mai 2010
Database Handling 
• CodeIgniter provides a simple way 
to access the database. 
• It encapsulates the underlying 
database (MySQL, Oracle, etc) 
• The connection handling is done by 
CodeIgniter and configured through: 
/application/config/database.php 
• Provides security through automatic 
escaping of inserted data, avoids 
Cross-Side Scripting (CSS) attacks 
Initializing the Database Class 
$this->load->database(); 
Standard Query With Multiple Results 
$query = $this->db->query('SELECT name, 
title, email FROM my_table'); 
foreach ($query->result() as $row) 
{ 
echo $row->title; 
echo $row->name; 
echo $row->email; 
} 
echo 'Total Results: ' . $query->num_rows(); 
Database Configuration 
$db['test']['hostname'] = "localhost"; 
$db['test']['username'] = "root"; 
$db['test']['password'] = ""; 
$db['test']['database'] = "database_name"; 
$db['test']['dbdriver'] = "mysql"; 
$db['test']['dbprefix'] = ""; 
$db['test']['pconnect'] = TRUE; 
$db['test']['db_debug'] = FALSE; 
$db['test']['cache_on'] = FALSE; 
$db['test']['cachedir'] = ""; 
$db['test']['char_set'] = "utf8"; 
$db['test']['dbcollat'] = "utf8_general_ci"; 
Dienstag, 4. Mai 2010
Active Records 
• CodeIgniter uses a modified version of 
the Active Record Database Pattern. 
• This pattern allows information to be 
retrieved, inserted, and updated in 
your database with minimal scripting. 
Selecting Data 
Inserting Data 
Method Chaining 
Dienstag, 4. Mai 2010
Application Profiling 
• The Profiler Class will display 
benchmark results, queries you 
have run, and $_POST data at 
the bottom of your pages. 
• This information can be useful 
during development in order to 
help with debugging and 
optimization. 
• Enabling the Profiler 
somewhere in the Controller: 
$this->output->enable_profiler(TRUE); 
Dienstag, 4. Mai 2010
Further Reading and Resources 
• CodeIgniter User Guide: 
http://codeigniter.com/user_guide/index.html 
• Tutorials and Video Tutorials: 
http://codeigniter.com/wiki/Category:Help::Tutorials 
• Model-View-Controller and CodeIgniter: 
http://www.zenperfect.com/2007/07/12/model-view-controller-and-codeigniter/ 
Dienstag, 4. Mai 2010

More Related Content

What's hot

Super Fast Application development with Mura CMS
Super Fast Application development with Mura CMSSuper Fast Application development with Mura CMS
Super Fast Application development with Mura CMS
ColdFusionConference
 
You Got React.js in My PHP
You Got React.js in My PHPYou Got React.js in My PHP
You Got React.js in My PHP
Taylor Lovett
 
Saving Time with WP-CLI
Saving Time with WP-CLISaving Time with WP-CLI
Saving Time with WP-CLI
Taylor Lovett
 
WordPress Security by Nirjhor Anjum
WordPress Security by Nirjhor AnjumWordPress Security by Nirjhor Anjum
WordPress Security by Nirjhor Anjum
Abul Khayer
 
Web API Basics
Web API BasicsWeb API Basics
Web API Basics
LearnNowOnline
 
Introdcution to Adobe CQ
Introdcution to Adobe CQIntrodcution to Adobe CQ
Introdcution to Adobe CQ
Rest West
 
Introduction to Monsoon PHP framework
Introduction to Monsoon PHP frameworkIntroduction to Monsoon PHP framework
Introduction to Monsoon PHP framework
Krishna Srikanth Manda
 
Here Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressHere Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPress
Rami Sayar
 
Building search app with ElasticSearch
Building search app with ElasticSearchBuilding search app with ElasticSearch
Building search app with ElasticSearch
Lukas Vlcek
 
Managing Multisite: Lessons from a Large Network
Managing Multisite: Lessons from a Large NetworkManaging Multisite: Lessons from a Large Network
Managing Multisite: Lessons from a Large Network
William Earnhardt
 
WordPress as a CMS - Case Study of an Organizational Intranet
WordPress as a CMS - Case Study of an Organizational IntranetWordPress as a CMS - Case Study of an Organizational Intranet
WordPress as a CMS - Case Study of an Organizational IntranetTech Liminal
 
4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
Manolis Vavalis
 
HTML5 Local Storage
HTML5 Local StorageHTML5 Local Storage
HTML5 Local Storage
Lior Zamir
 
Speeding up your WordPress Site - WordCamp Toronto 2015
Speeding up your WordPress Site - WordCamp Toronto 2015Speeding up your WordPress Site - WordCamp Toronto 2015
Speeding up your WordPress Site - WordCamp Toronto 2015
Alan Lok
 
Sightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVASightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVA
Yash Mody
 
Piecing Together the WordPress Puzzle
Piecing Together the WordPress PuzzlePiecing Together the WordPress Puzzle
Piecing Together the WordPress Puzzle
Business Vitality LLC
 
Web Servers, Browsers, Server - Browser Interaction, Web Surfing
Web Servers, Browsers, Server - Browser Interaction, Web SurfingWeb Servers, Browsers, Server - Browser Interaction, Web Surfing
Web Servers, Browsers, Server - Browser Interaction, Web Surfingwebhostingguy
 
Modernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchModernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with Elasticsearch
Taylor Lovett
 

What's hot (20)

Super Fast Application development with Mura CMS
Super Fast Application development with Mura CMSSuper Fast Application development with Mura CMS
Super Fast Application development with Mura CMS
 
You Got React.js in My PHP
You Got React.js in My PHPYou Got React.js in My PHP
You Got React.js in My PHP
 
Saving Time with WP-CLI
Saving Time with WP-CLISaving Time with WP-CLI
Saving Time with WP-CLI
 
WordPress Security by Nirjhor Anjum
WordPress Security by Nirjhor AnjumWordPress Security by Nirjhor Anjum
WordPress Security by Nirjhor Anjum
 
Web API Basics
Web API BasicsWeb API Basics
Web API Basics
 
Ch. 11 deploying
Ch. 11 deployingCh. 11 deploying
Ch. 11 deploying
 
Introdcution to Adobe CQ
Introdcution to Adobe CQIntrodcution to Adobe CQ
Introdcution to Adobe CQ
 
Introduction to Monsoon PHP framework
Introduction to Monsoon PHP frameworkIntroduction to Monsoon PHP framework
Introduction to Monsoon PHP framework
 
Here Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressHere Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPress
 
Building search app with ElasticSearch
Building search app with ElasticSearchBuilding search app with ElasticSearch
Building search app with ElasticSearch
 
Managing Multisite: Lessons from a Large Network
Managing Multisite: Lessons from a Large NetworkManaging Multisite: Lessons from a Large Network
Managing Multisite: Lessons from a Large Network
 
WordPress as a CMS - Case Study of an Organizational Intranet
WordPress as a CMS - Case Study of an Organizational IntranetWordPress as a CMS - Case Study of an Organizational Intranet
WordPress as a CMS - Case Study of an Organizational Intranet
 
4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
 
HTML5 Local Storage
HTML5 Local StorageHTML5 Local Storage
HTML5 Local Storage
 
Local storage
Local storageLocal storage
Local storage
 
Speeding up your WordPress Site - WordCamp Toronto 2015
Speeding up your WordPress Site - WordCamp Toronto 2015Speeding up your WordPress Site - WordCamp Toronto 2015
Speeding up your WordPress Site - WordCamp Toronto 2015
 
Sightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVASightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVA
 
Piecing Together the WordPress Puzzle
Piecing Together the WordPress PuzzlePiecing Together the WordPress Puzzle
Piecing Together the WordPress Puzzle
 
Web Servers, Browsers, Server - Browser Interaction, Web Surfing
Web Servers, Browsers, Server - Browser Interaction, Web SurfingWeb Servers, Browsers, Server - Browser Interaction, Web Surfing
Web Servers, Browsers, Server - Browser Interaction, Web Surfing
 
Modernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchModernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with Elasticsearch
 

Similar to Codeigniter

Codeigniter
CodeigniterCodeigniter
Codeigniter
ShahRushika
 
Php reports sumit
Php reports sumitPhp reports sumit
Php reports sumit
Sumit Biswas
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
Taylor Lovett
 
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Lucidworks
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPress
Taylor Lovett
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
Henry S
 
Introduction To CodeIgniter
Introduction To CodeIgniterIntroduction To CodeIgniter
Introduction To CodeIgniter
Muhammad Hafiz Hasan
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code Igniter
Amzad Hossain
 
Codeinator
CodeinatorCodeinator
Php intro
Php introPhp intro
Php intro
Jennie Gajjar
 
SOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesSOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class Libraries
Vagif Abilov
 
Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty
reedmaniac
 
BackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applicationsBackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applications
Joseph Khan
 
Get things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGet things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplications
Giuliano Iacobelli
 
MVCL pattern, web flow, code flow, request and response in OpenCart
MVCL pattern, web flow, code flow, request and response in OpenCartMVCL pattern, web flow, code flow, request and response in OpenCart
MVCL pattern, web flow, code flow, request and response in OpenCart
Self
 
Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty
Leslie Doherty
 

Similar to Codeigniter (20)

Codeigniter framework
Codeigniter framework Codeigniter framework
Codeigniter framework
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Php reports sumit
Php reports sumitPhp reports sumit
Php reports sumit
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
 
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPress
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
 
Introduction To CodeIgniter
Introduction To CodeIgniterIntroduction To CodeIgniter
Introduction To CodeIgniter
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code Igniter
 
Codeinator
CodeinatorCodeinator
Codeinator
 
Php intro
Php introPhp intro
Php intro
 
Php intro
Php introPhp intro
Php intro
 
Php intro
Php introPhp intro
Php intro
 
SOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesSOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class Libraries
 
Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty
 
presentation
presentationpresentation
presentation
 
BackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applicationsBackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applications
 
Get things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGet things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplications
 
MVCL pattern, web flow, code flow, request and response in OpenCart
MVCL pattern, web flow, code flow, request and response in OpenCartMVCL pattern, web flow, code flow, request and response in OpenCart
MVCL pattern, web flow, code flow, request and response in OpenCart
 
Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty
 

Recently uploaded

Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 

Recently uploaded (20)

Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 

Codeigniter

  • 1. CodeIgniter and MVC Enterprise class web application development Dienstag, 4. Mai 2010
  • 2. Motivation • You have worked with PHP, for small sites this works very well. HTML files can be easily extended with dynamic content from the database, form processing, etc. • When sites grow, you might have realized that across multiple pages lots of code repetition occurs. This is a problem when you need to change certain parts of a page, that affects many or all pages. • Furthermore, its hard to introduce new developers to code someone else has written. It takes a long time to get familar with the code. Dienstag, 4. Mai 2010
  • 3. Motivation • Enterprise class (big) web applications need structure, one HTML file per page with PHP code is not optimal => things get confusing, hard to work in teams, etc. • Web Application Frameworks provide such a structure wich introduce seperation of concern, etc. • Most common for Web application development are frameworks that are based on the Model-View-Controller design pattern • Motivation video for a MVC framework: http://www.youtube.com/watch?v=p5EIrSM8dCA Dienstag, 4. Mai 2010
  • 4. Model-View-Controller • „Seperation of concerns“ of Logic and Presentation • Controller: Handles all incoming HTTP requests, passes data to the views • View: Renders the HTML output • Models: Encapsulate Business Logic, such as interaction with the database • For PHP we introduce CodeIgniter Dienstag, 4. Mai 2010
  • 5. CodeIgniter • CodeIgniter is a PHP-based MVC framework that helps structure your code and make redundant tasks less tedious. • There are countless similar PHP frameworks, the most popular ones being CakePHP and symfony. Ruby on Rails is famous in the Ruby world. • CodeIgniter is very light weight. It doesn‘t force any convention but provides many commonly required features through a set of build in libraries. • CodeIgniter has a low learning curve and is one of the best documented PHP web frameworks. Dienstag, 4. Mai 2010
  • 6. CodeIgniter: Features • Model-View-Controller Based System • Extremely Light Weight, does not force any convention • Full Featured database classes with support for several platforms, Active Record Database Support (ORM) • Custom Routing • Form and Data Validation • Security and XSS Filtering Dienstag, 4. Mai 2010
  • 7. Application Flow Chart 1. The index.php serves as the front controller, initializing the base resources needed to run CodeIgniter. 2. The Router examines the HTTP request to determine what should be done with it. 3. If a cache file exists, it is sent directly to the browser, bypassing the normal system execution. 4. Security. Before the application controller is loaded, the HTTP request and any user submitted data is filtered for security. 5. The Controller loads the model, core libraries, plugins, helpers, and any other resources needed to process the specific request. 6. The finalized View is rendered then sent to the web browser to be seen. If caching is enabled, the view is cached first so that on subsequent requests it can be served. Dienstag, 4. Mai 2010
  • 8. Getting Started • Directory Structure of CodeIgniter: • index.php - recieves all requests and routes to the right controllers classes and actions, parameters are included in the URL • /system - contains all CodeIgniter classes and libraries provided by the framework • /application - this is where your application code is located, including the model, view and controller classes Dienstag, 4. Mai 2010
  • 9. Controllers • Take incoming HTTP requests and process them • Must be the same filename as the capitalized class name • Must extend the main Controller class of CodeIgniter • Each class function represents an controller action, which is redering a HTML page • „index“ is the default action Dienstag, 4. Mai 2010
  • 10. Routing Requests • Per default CodeIgniter maps URL to controller actions: /index.php/controller/action • The default controller is „welcome“ and the default action is „index“. • Custom routing can be configured through: /application/config/routes.php Dienstag, 4. Mai 2010
  • 11. Views • Are HTML pages or page fragments • Those are load and sent by the Controller to the Browser by the use of the following code in den Ctrl: $this->load->view(‘blog_view‘); • There is no application logic in the views, only display logic (to some degree) • <?= is short form for <?php echo Dienstag, 4. Mai 2010
  • 12. Controller & View sample Dienstag, 4. Mai 2010
  • 13. Helpers • Helper functions are located in /application/helpers/ • These are small PHP functions that provide shortcuts, to outsource often used code • For example formatting, text, url or form helpers • Needs to be loaded through: $this->load->helper(‘name‘); Loading a Helper $this->load->helper('name'); Using a Helper <?php echo anchor('blog/comments', 'Click Here');?> Auto-loading Helpers application/config/autoload.php Text Helper $this->load->helper('text'); word_limiter() $string = "Here is a nice text string consisting of eleven words."; $string = word_limiter($string, 4); // Returns: Here is a nice… Dienstag, 4. Mai 2010
  • 14. Libraries • Libraries are similar to helpers • The also need to be loaded through: $this->load->library('classname'); • The difference is that they encapsulate more complex functionality, such as image processing, form validation handling, caching, etc. • Libraries allow to dynamically extend CodeIgniters functionality and extendability Dienstag, 4. Mai 2010
  • 15. Database Handling • CodeIgniter provides a simple way to access the database. • It encapsulates the underlying database (MySQL, Oracle, etc) • The connection handling is done by CodeIgniter and configured through: /application/config/database.php • Provides security through automatic escaping of inserted data, avoids Cross-Side Scripting (CSS) attacks Initializing the Database Class $this->load->database(); Standard Query With Multiple Results $query = $this->db->query('SELECT name, title, email FROM my_table'); foreach ($query->result() as $row) { echo $row->title; echo $row->name; echo $row->email; } echo 'Total Results: ' . $query->num_rows(); Database Configuration $db['test']['hostname'] = "localhost"; $db['test']['username'] = "root"; $db['test']['password'] = ""; $db['test']['database'] = "database_name"; $db['test']['dbdriver'] = "mysql"; $db['test']['dbprefix'] = ""; $db['test']['pconnect'] = TRUE; $db['test']['db_debug'] = FALSE; $db['test']['cache_on'] = FALSE; $db['test']['cachedir'] = ""; $db['test']['char_set'] = "utf8"; $db['test']['dbcollat'] = "utf8_general_ci"; Dienstag, 4. Mai 2010
  • 16. Active Records • CodeIgniter uses a modified version of the Active Record Database Pattern. • This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting. Selecting Data Inserting Data Method Chaining Dienstag, 4. Mai 2010
  • 17. Application Profiling • The Profiler Class will display benchmark results, queries you have run, and $_POST data at the bottom of your pages. • This information can be useful during development in order to help with debugging and optimization. • Enabling the Profiler somewhere in the Controller: $this->output->enable_profiler(TRUE); Dienstag, 4. Mai 2010
  • 18. Further Reading and Resources • CodeIgniter User Guide: http://codeigniter.com/user_guide/index.html • Tutorials and Video Tutorials: http://codeigniter.com/wiki/Category:Help::Tutorials • Model-View-Controller and CodeIgniter: http://www.zenperfect.com/2007/07/12/model-view-controller-and-codeigniter/ Dienstag, 4. Mai 2010