SlideShare a Scribd company logo
1 of 36
Download to read offline
CodeIgniter
A brief introduction
https://github.com/bcit-ci/CodeIgniter
http://www.codeigniter.com/
What is it?
CI is a HMVC framework for rapid PHP web application
development.
It’s focused on performance, ease of use and minimal
configuration.
MVC pattern is encouraged but not enforced.
What is it?
It has been mantained by EllisLab until 2014 ( http:
//ellislab.com/ ) . Since then the code is mantained by
British Columbia Institute of Technology ( http://bcit.ca/ )
Find the contributors list on the GitHub project page:
https://github.com/bcit-
ci/CodeIgniter/graphs/contributors
Why using it
● Flexible and easy to extend
● Lightweight and performant
● Noob friendly
● Minimal configuration
● It can use templating engines, but doesn’t need one
● VERY well documented
● CI Sparks / Composer
● Active community
Main features
● HMVC architecture
● Query-builder database support
● Drivers for main DBMS systems (MySQL,
MS SQL Server, Postgres, Oracle etc...)
● CSRF and XSS Filtering
● Session management
● Benchmarking
Main features
● Image manipulation (requires GD, ImageMagick
or NetPBM)
● Email library
● Uploading
● Caching
● CLI interface
● Internationalization
● … too many to be listed here.
Architectural goals
● Dynamic instantiation: libraries and helpers are loaded
by controllers on demand when they are needed, keeping
the system light and reactive
● Components singularity: each class and its functions are
highly autonomous in order to allow maximum usefulness
● Loose coupling: each component minimizes its reliance
on other components, becoming more reusable.
Requirements
● PHP 5.2.4 (5.4 is recommended)
● A Web Server
Remind that, as of PHP 5.4, the interpreter
provides a built-in web server to test your
applications. So you do not really need a stand
alone web server to start developing.
application/config/config.php holds most of the
configuration you need to start developing your
application, such as base_url (e.g. http://google.
com/, if Google was written with CI), URLs suffixes,
default charsets, locales, hooks configuration,
Composer integration and much more.
Basic configuration
Routing & Controllers
Preliminar note: CI provides a index.php script which triggers the
framework lifecycle for each request.
To remove index.php from URL and to route every request to it, you can
use mod_rewrite on Apache like this https://gist.github.
com/sixpounder/c61e660b43c0aa2b9356
For PHP builtin server look at this GIST https://gist.github.
com/sixpounder/6758cddd83330125bc10
From now on we assume index.php to be removed from URLs.
Routing & Controllers
A request lifecycle in CI
Routing & Controllers
CI URLs are basically query string arguments to
index.php. They are made of URI segments that
represent (by default, but this can be changed in
application/config/config.php by defining custom
routes) the controller and the method
responsible for serving a request mapped on
that specific URL.
Routing & Controllers
example.com/news/article/ID
● The first segment represents the controller class to be
invoked
● The second segment represents the controller instance
method that will be executed (assuming index if not
specified)
● The third (and any further) segment represents an
additional parameter that will be passed to the
controller method as an argument.
Routing & Controllers
● These URLs are SEO-friendly!
● You can organize controllers in sub folders. In this case,
the initial URI segments will represent your folder
structure.
● Classic query strings are available
● You can add URLs suffixes
● You can define overrides, custom URI routings and the
default controller in application/config/routes.php
Routing & Controllers
Controller classes extend CI_Controller and must be
placed in application/controllers. Class name must have
its first letter capitalized and it must match the file
name.
/* application/controllers/Article.php */
class Article extends CI_Controller { … }
Models are classes that interacts with your
database. CI doesn’t provide an ORM like
Rails Active Record, rather it provides a
Query Builder that builds queries by
masking the underlying physical DBMS
implementation.
Models
Models
● Models should be indepent from the components
that use them
● Query Builder supports transactions
● Database Forge Class can be used to manage the
physical structure of your database (so you do not
have the responsability to do so!)
● Support for migrations (by extending CI_Migration)
Models
To load and use a model inside a controller:
$this->load->model(‘model_name’);
Models must be placed in application/models. Classes
and file names must have their first letter capitalized
and the rest of the name lowercase. They must extend
CI_Model.
Views & Templating
CI’s core provides different ways of sending
an output to a client, like basic view
rendering, simple template parsing and
direct output control. All these methods are
wrapped into core libraries.
Views & Templating
View rendering
A view is simply a web page, or a page fragment, like a header, footer,
sidebar, etc. In fact, views can flexibly be embedded within other views
(within other views, etc., etc.) if you need this type of hierarchy.
Views are stored by default in application/views directory and have .php
extension (unless you need something different, eg. if you are using twig).
A controller can render a view by loading it like this:
$this->load->view(‘viewname’);
Views & Templating
View rendering
Data is passed from the controller to the view by way of
an array or an object in the second parameter of the
view loading method.
$data = array('title' => 'My Title','heading' => 'My Heading','message' => 'My
Message');
$this->load->view('blogview', $data);
Views & Templating
View rendering
A third boolean argument may be provided to the view
loader. If it is present and its value is TRUE the method
returns the string representation of the finalized view.
This can be usefull for templating purposes.
$data = array('title' => 'My Title','heading' => 'My Heading','body' => 'Article
body');
var $content = $this->load->view('article', $data, TRUE);
Views & Templating
Output Library
The Output Library is used under-the-hood by the view
loader to finalize the output before sending it to the
client. It can be directly used, for instance, to send a
JSON output if you are dealing with a REST API, or a file’s
content if you are writing a file server and so on.
Views & Templating
JSON example
$this->output->set_content_type('application/json')->set_output(json_encode(array
('foo' => 'bar')));
Sending an image
$this->output->set_content_type('jpeg')->set_output(file_get_contents
('files/something.jpg'));
HINT: The _display() method is called automatically at the end of script execution, you won’t need
to call it manually unless you are aborting script execution using exit() or die() in your code.
Calling it without aborting script execution will result in duplicate output.
Views & Templating
Template Parser
The Template Parser Library can parse simple templates
by operating basic substitutions of pseudo-variables
contained in your views.
Pseudo variables must be enclosed in braces.
Views & Templating
Template Parser
$this->load->library('parser');
$data = array(
'blog_title' => 'Six Blog',
'blog_heading' => 'A blog about computing',
'blog_entries' => array(
array('title' => 'Title 1', 'body' => 'Body 1'),
array('title' => 'Title 2', 'body' => 'Body 2'),
array('title' => 'Title 3', 'body' => 'Body 3'),
array('title' => 'Title 4', 'body' => 'Body 4'),
array('title' => 'Title 5', 'body' => 'Body 5')
)
); // This could be the result of a query as well!
$this->parser->parse(tpl', $data);
Views & Templating
<html>
<head>
<title>{blog_title}</title>
</head>
<body>
<h3>{blog_heading}</h3>
{blog_entries}
<h5>{title}</h5>
<p>{body}</p>
{/blog_entries}
</body>
</html>
Basic substitution
blog_entries is an array
and this is a render
cycle
Libraries & Helpers
CI provides a bunch of libraries and helpers.
We already saw the Output library (one of
the few libraries that are auto loaded by CI
itself), but there are many more.
Libraries & Helpers
Benchmarking Class
Caching Driver
Calendaring Class
Shopping Cart Class
Config Class
Email Class
Encrypt Class
Encryption Library
File Uploading Class
Form Validation
FTP Class
Image Manipulation Class
Input Class
Javascript Class
Language Class
Loader Class
Migrations Class
Output Class
Pagination Class
Template Parser Class
Security Class
Session Library
HTML Table Class
Trackback Class
Typography Class
Unit Testing Class
URI Class
User Agent Class
XML-RPC and XML-RPC Server Classes
Zip Encoding Class
Libraries & Helpers
Helpers, as the name suggests, help you with tasks. Each
helper file is simply a collection of functions in a particular
category.
There are URL Helpers, that assist in creating links, there are
Form Helpers that help you create form elements, Text
Helpers perform various text formatting routines, Cookie
Helpers set and read cookies, File Helpers help you deal with
files, etc
Libraries & Helpers
Array Helper
CAPTCHA Helper
Cookie Helper
Date Helper
Directory Helper
Download Helper
Email Helper
File Helper
Form Helper
HTML Helper
Inflector Helper
Language Helper
Number Helper
Path Helper
Security Helper
Smiley Helper
String Helper
Text Helper
Typography Helper
URL Helper
XML Helper
Extending CodeIgniter
CI provides many ways to extend the framework
● Custom libraries
● Estensione system libraries
● Hooks
● Sparks plugins ( http://getsparks.org/ )
● Easy integration with Composer
Extending CodeIgniter
You can replace or extend the system libraries provided by CI.
To replace them with your own implementation,simply create a
library with the same name as the one you want to replace in
application/libraries.
To extend them, create a new class prefixed by the default extender
prefix (see application/config/config.php), like this:
class MY_Email extends CI_Email { … }
Extending CodeIgniter
With hooks you can tap into the framework
core and modify its behaviour without
hacking the core files
Extending CodeIgniter
Defining a hook
in application/config/hooks.php each key in $hook represents a script at a certain point of the
application lifecycle:
$hook['pre_controller'] = array(
'class' => 'MyClass',
'function' => 'Myfunction',
'filename' => 'Myclass.php',
'filepath' => 'hooks',
'params' => array('beer', 'wine', 'snacks')
);
Available hook points are: pre_system, pre_controller, post_controller_constructor,
post_controller, display_override, cache_override, post_system.
Q & A

More Related Content

What's hot

Soap web service
Soap web serviceSoap web service
Soap web serviceNITT, KAMK
 
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptxGetting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptxIlesh Mistry
 
Introduction to Django REST Framework, an easy way to build REST framework in...
Introduction to Django REST Framework, an easy way to build REST framework in...Introduction to Django REST Framework, an easy way to build REST framework in...
Introduction to Django REST Framework, an easy way to build REST framework in...Zhe Li
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentationivpol
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptAndres Baravalle
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC PresentationVolkan Uzun
 
Full-Stack Development
Full-Stack DevelopmentFull-Stack Development
Full-Stack DevelopmentDhilipsiva DS
 
Django Rest Framework - Building a Web API
Django Rest Framework - Building a Web APIDjango Rest Framework - Building a Web API
Django Rest Framework - Building a Web APIMarcos Pereira
 
Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | IntroductionJohnTaieb
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux IntroductionNikolaus Graf
 

What's hot (20)

Soap web service
Soap web serviceSoap web service
Soap web service
 
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptxGetting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptx
 
Introduction to Django REST Framework, an easy way to build REST framework in...
Introduction to Django REST Framework, an easy way to build REST framework in...Introduction to Django REST Framework, an easy way to build REST framework in...
Introduction to Django REST Framework, an easy way to build REST framework in...
 
Lecture 7: Server side programming
Lecture 7: Server side programmingLecture 7: Server side programming
Lecture 7: Server side programming
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Php
PhpPhp
Php
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
CodeIgniter 101 Tutorial
CodeIgniter 101 TutorialCodeIgniter 101 Tutorial
CodeIgniter 101 Tutorial
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Full-Stack Development
Full-Stack DevelopmentFull-Stack Development
Full-Stack Development
 
Django Rest Framework - Building a Web API
Django Rest Framework - Building a Web APIDjango Rest Framework - Building a Web API
Django Rest Framework - Building a Web API
 
Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | Introduction
 
Flask Basics
Flask BasicsFlask Basics
Flask Basics
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
Rest api with Python
Rest api with PythonRest api with Python
Rest api with Python
 

Viewers also liked

PHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterPHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterJamshid Hashimi
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkBo-Yi Wu
 
Introduction To CodeIgniter
Introduction To CodeIgniterIntroduction To CodeIgniter
Introduction To CodeIgniterschwebbie
 
Txesus Zubiate | landscape version portfolio
Txesus Zubiate | landscape version portfolioTxesus Zubiate | landscape version portfolio
Txesus Zubiate | landscape version portfolioTxesus Zubiate
 
Right Turn e Design - BNI 8 Min Presentation
Right Turn e Design - BNI 8 Min Presentation Right Turn e Design - BNI 8 Min Presentation
Right Turn e Design - BNI 8 Min Presentation Right Turn e Design
 
Introduction to CodeIgniter
Introduction to CodeIgniterIntroduction to CodeIgniter
Introduction to CodeIgniterPiti Suwannakom
 
Having fun with code igniter
Having fun with code igniterHaving fun with code igniter
Having fun with code igniterAhmad Arif
 
Front End Innovation - Peter Koen
Front End Innovation - Peter KoenFront End Innovation - Peter Koen
Front End Innovation - Peter KoenBrand Genetics
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code IgniterAmzad Hossain
 
Introduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterIntroduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterPongsakorn U-chupala
 
Continuous Improvement Project
Continuous Improvement ProjectContinuous Improvement Project
Continuous Improvement ProjectDarlene Lebaste
 
MySQL Atchitecture and Concepts
MySQL Atchitecture and ConceptsMySQL Atchitecture and Concepts
MySQL Atchitecture and ConceptsTuyen Vuong
 
Introduction to codeigniter
Introduction to codeigniterIntroduction to codeigniter
Introduction to codeigniterHarishankaran K
 
A PROJECT REPORT ON EXPORT PROCESS AND DOCUMENTATION
A PROJECT REPORT ON EXPORT PROCESS AND DOCUMENTATIONA PROJECT REPORT ON EXPORT PROCESS AND DOCUMENTATION
A PROJECT REPORT ON EXPORT PROCESS AND DOCUMENTATIONSagar Anand
 

Viewers also liked (20)

PHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterPHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniter
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Introduction To CodeIgniter
Introduction To CodeIgniterIntroduction To CodeIgniter
Introduction To CodeIgniter
 
Txesus Zubiate | landscape version portfolio
Txesus Zubiate | landscape version portfolioTxesus Zubiate | landscape version portfolio
Txesus Zubiate | landscape version portfolio
 
Right Turn e Design - BNI 8 Min Presentation
Right Turn e Design - BNI 8 Min Presentation Right Turn e Design - BNI 8 Min Presentation
Right Turn e Design - BNI 8 Min Presentation
 
Introduction to CodeIgniter
Introduction to CodeIgniterIntroduction to CodeIgniter
Introduction to CodeIgniter
 
Having fun with code igniter
Having fun with code igniterHaving fun with code igniter
Having fun with code igniter
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Front End Innovation - Peter Koen
Front End Innovation - Peter KoenFront End Innovation - Peter Koen
Front End Innovation - Peter Koen
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code Igniter
 
Introduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterIntroduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniter
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
Introduction to MySQL
Introduction to MySQLIntroduction to MySQL
Introduction to MySQL
 
Continuous Improvement Project
Continuous Improvement ProjectContinuous Improvement Project
Continuous Improvement Project
 
MySQL Atchitecture and Concepts
MySQL Atchitecture and ConceptsMySQL Atchitecture and Concepts
MySQL Atchitecture and Concepts
 
Introduction to Mysql
Introduction to MysqlIntroduction to Mysql
Introduction to Mysql
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
Introduction to codeigniter
Introduction to codeigniterIntroduction to codeigniter
Introduction to codeigniter
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
A PROJECT REPORT ON EXPORT PROCESS AND DOCUMENTATION
A PROJECT REPORT ON EXPORT PROCESS AND DOCUMENTATIONA PROJECT REPORT ON EXPORT PROCESS AND DOCUMENTATION
A PROJECT REPORT ON EXPORT PROCESS AND DOCUMENTATION
 

Similar to Code igniter - A brief introduction

Asp.net With mvc handson
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handsonPrashant Kumar
 
IRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHPIRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHPIRJET Journal
 
Overview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company indiaOverview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company indiaJignesh Aakoliya
 
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009Monorail presentation at WebDevelopersCommunity, Feb 1, 2009
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009ken.egozi
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep DiveGabriel Walt
 
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 webapplicationsGiuliano Iacobelli
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docxfantabulous2024
 
MVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on RailsMVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on Railscodeinmotion
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101Rich Helton
 
Innovate2011 Keys to Building OSLC Integrations
Innovate2011 Keys to Building OSLC IntegrationsInnovate2011 Keys to Building OSLC Integrations
Innovate2011 Keys to Building OSLC IntegrationsSteve Speicher
 
PHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniterPHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniterKHALID C
 
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 1Henry S
 
Getting Started with Zend Framework
Getting Started with Zend FrameworkGetting Started with Zend Framework
Getting Started with Zend FrameworkJuan Antonio
 
Codeigniter simple explanation
Codeigniter simple explanation Codeigniter simple explanation
Codeigniter simple explanation Arumugam P
 
Html5 deciphered - designing concepts part 1
Html5 deciphered - designing concepts part 1Html5 deciphered - designing concepts part 1
Html5 deciphered - designing concepts part 1Paxcel Technologies
 
Nasdanika Foundation Server
Nasdanika Foundation ServerNasdanika Foundation Server
Nasdanika Foundation ServerPavel Vlasov
 

Similar to Code igniter - A brief introduction (20)

Asp.net With mvc handson
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handson
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
IRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHPIRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHP
 
Overview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company indiaOverview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company india
 
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009Monorail presentation at WebDevelopersCommunity, Feb 1, 2009
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
 
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
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docx
 
MVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on RailsMVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on Rails
 
Mvc
MvcMvc
Mvc
 
sveltekit-en.pdf
sveltekit-en.pdfsveltekit-en.pdf
sveltekit-en.pdf
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101
 
Knolx session
Knolx sessionKnolx session
Knolx session
 
Innovate2011 Keys to Building OSLC Integrations
Innovate2011 Keys to Building OSLC IntegrationsInnovate2011 Keys to Building OSLC Integrations
Innovate2011 Keys to Building OSLC Integrations
 
PHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniterPHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniter
 
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
 
Getting Started with Zend Framework
Getting Started with Zend FrameworkGetting Started with Zend Framework
Getting Started with Zend Framework
 
Codeigniter simple explanation
Codeigniter simple explanation Codeigniter simple explanation
Codeigniter simple explanation
 
Html5 deciphered - designing concepts part 1
Html5 deciphered - designing concepts part 1Html5 deciphered - designing concepts part 1
Html5 deciphered - designing concepts part 1
 
Nasdanika Foundation Server
Nasdanika Foundation ServerNasdanika Foundation Server
Nasdanika Foundation Server
 

More from Commit University

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
Breaking REST Chains_ A Fastify & Mercurius Pathway to GraphQL Glory.pdf
Breaking REST Chains_ A Fastify & Mercurius Pathway to GraphQL Glory.pdfBreaking REST Chains_ A Fastify & Mercurius Pathway to GraphQL Glory.pdf
Breaking REST Chains_ A Fastify & Mercurius Pathway to GraphQL Glory.pdfCommit University
 
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-Slide.pdf
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-Slide.pdfAccelerating API Development: A Pit Stop with Gin-Gonic in Golang-Slide.pdf
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-Slide.pdfCommit University
 
Collaborazione, Decisionalità e Gestione della Complessità nel Tempo: cosa ...
Collaborazione, Decisionalità e Gestione della Complessità nel Tempo: cosa ...Collaborazione, Decisionalità e Gestione della Complessità nel Tempo: cosa ...
Collaborazione, Decisionalità e Gestione della Complessità nel Tempo: cosa ...Commit University
 
Commit - Qwik il framework che ti stupirà.pptx
Commit - Qwik il framework che ti stupirà.pptxCommit - Qwik il framework che ti stupirà.pptx
Commit - Qwik il framework che ti stupirà.pptxCommit University
 
Sviluppare da zero una Angular Web App per la PA
Sviluppare da zero una Angular Web App per la PASviluppare da zero una Angular Web App per la PA
Sviluppare da zero una Angular Web App per la PACommit University
 
Backstage l'Internal Developer Portal Open Source per una migliore Developer ...
Backstage l'Internal Developer Portal Open Source per una migliore Developer ...Backstage l'Internal Developer Portal Open Source per una migliore Developer ...
Backstage l'Internal Developer Portal Open Source per una migliore Developer ...Commit University
 
Prisma the ORM that node was waiting for
Prisma the ORM that node was waiting forPrisma the ORM that node was waiting for
Prisma the ORM that node was waiting forCommit University
 
Decision-making for Software Development Teams - Commit University
Decision-making for Software Development Teams - Commit UniversityDecision-making for Software Development Teams - Commit University
Decision-making for Software Development Teams - Commit UniversityCommit University
 
Component Design Pattern nei Game Engine.pdf
Component Design Pattern nei Game Engine.pdfComponent Design Pattern nei Game Engine.pdf
Component Design Pattern nei Game Engine.pdfCommit University
 
Un viaggio alla scoperta dei Language Models e dell’intelligenza artificiale ...
Un viaggio alla scoperta dei Language Models e dell’intelligenza artificiale ...Un viaggio alla scoperta dei Language Models e dell’intelligenza artificiale ...
Un viaggio alla scoperta dei Language Models e dell’intelligenza artificiale ...Commit University
 
Prototipazione Low-Code con AWS Step Functions
Prototipazione Low-Code con AWS Step FunctionsPrototipazione Low-Code con AWS Step Functions
Prototipazione Low-Code con AWS Step FunctionsCommit University
 
KMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and SwiftKMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and SwiftCommit University
 
Da Vuex a Pinia: come fare la migrazione
Da Vuex a Pinia: come fare la migrazioneDa Vuex a Pinia: come fare la migrazione
Da Vuex a Pinia: come fare la migrazioneCommit University
 
Orchestrare Micro-frontend con micro-lc
Orchestrare Micro-frontend con micro-lcOrchestrare Micro-frontend con micro-lc
Orchestrare Micro-frontend con micro-lcCommit University
 
Fastify has defeated Lagacy-Code
Fastify has defeated Lagacy-CodeFastify has defeated Lagacy-Code
Fastify has defeated Lagacy-CodeCommit University
 

More from Commit University (20)

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
Breaking REST Chains_ A Fastify & Mercurius Pathway to GraphQL Glory.pdf
Breaking REST Chains_ A Fastify & Mercurius Pathway to GraphQL Glory.pdfBreaking REST Chains_ A Fastify & Mercurius Pathway to GraphQL Glory.pdf
Breaking REST Chains_ A Fastify & Mercurius Pathway to GraphQL Glory.pdf
 
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-Slide.pdf
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-Slide.pdfAccelerating API Development: A Pit Stop with Gin-Gonic in Golang-Slide.pdf
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-Slide.pdf
 
Slide-10years.pdf
Slide-10years.pdfSlide-10years.pdf
Slide-10years.pdf
 
Collaborazione, Decisionalità e Gestione della Complessità nel Tempo: cosa ...
Collaborazione, Decisionalità e Gestione della Complessità nel Tempo: cosa ...Collaborazione, Decisionalità e Gestione della Complessità nel Tempo: cosa ...
Collaborazione, Decisionalità e Gestione della Complessità nel Tempo: cosa ...
 
Vue.js slots.pdf
Vue.js slots.pdfVue.js slots.pdf
Vue.js slots.pdf
 
Commit - Qwik il framework che ti stupirà.pptx
Commit - Qwik il framework che ti stupirà.pptxCommit - Qwik il framework che ti stupirà.pptx
Commit - Qwik il framework che ti stupirà.pptx
 
Sviluppare da zero una Angular Web App per la PA
Sviluppare da zero una Angular Web App per la PASviluppare da zero una Angular Web App per la PA
Sviluppare da zero una Angular Web App per la PA
 
Backstage l'Internal Developer Portal Open Source per una migliore Developer ...
Backstage l'Internal Developer Portal Open Source per una migliore Developer ...Backstage l'Internal Developer Portal Open Source per una migliore Developer ...
Backstage l'Internal Developer Portal Open Source per una migliore Developer ...
 
Prisma the ORM that node was waiting for
Prisma the ORM that node was waiting forPrisma the ORM that node was waiting for
Prisma the ORM that node was waiting for
 
Decision-making for Software Development Teams - Commit University
Decision-making for Software Development Teams - Commit UniversityDecision-making for Software Development Teams - Commit University
Decision-making for Software Development Teams - Commit University
 
Component Design Pattern nei Game Engine.pdf
Component Design Pattern nei Game Engine.pdfComponent Design Pattern nei Game Engine.pdf
Component Design Pattern nei Game Engine.pdf
 
Un viaggio alla scoperta dei Language Models e dell’intelligenza artificiale ...
Un viaggio alla scoperta dei Language Models e dell’intelligenza artificiale ...Un viaggio alla scoperta dei Language Models e dell’intelligenza artificiale ...
Un viaggio alla scoperta dei Language Models e dell’intelligenza artificiale ...
 
Prototipazione Low-Code con AWS Step Functions
Prototipazione Low-Code con AWS Step FunctionsPrototipazione Low-Code con AWS Step Functions
Prototipazione Low-Code con AWS Step Functions
 
KMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and SwiftKMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and Swift
 
Da Vuex a Pinia: come fare la migrazione
Da Vuex a Pinia: come fare la migrazioneDa Vuex a Pinia: come fare la migrazione
Da Vuex a Pinia: come fare la migrazione
 
Orchestrare Micro-frontend con micro-lc
Orchestrare Micro-frontend con micro-lcOrchestrare Micro-frontend con micro-lc
Orchestrare Micro-frontend con micro-lc
 
Fastify has defeated Lagacy-Code
Fastify has defeated Lagacy-CodeFastify has defeated Lagacy-Code
Fastify has defeated Lagacy-Code
 
SwiftUI vs UIKit
SwiftUI vs UIKitSwiftUI vs UIKit
SwiftUI vs UIKit
 

Recently uploaded

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Recently uploaded (20)

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

Code igniter - A brief introduction

  • 2. What is it? CI is a HMVC framework for rapid PHP web application development. It’s focused on performance, ease of use and minimal configuration. MVC pattern is encouraged but not enforced.
  • 3. What is it? It has been mantained by EllisLab until 2014 ( http: //ellislab.com/ ) . Since then the code is mantained by British Columbia Institute of Technology ( http://bcit.ca/ ) Find the contributors list on the GitHub project page: https://github.com/bcit- ci/CodeIgniter/graphs/contributors
  • 4. Why using it ● Flexible and easy to extend ● Lightweight and performant ● Noob friendly ● Minimal configuration ● It can use templating engines, but doesn’t need one ● VERY well documented ● CI Sparks / Composer ● Active community
  • 5. Main features ● HMVC architecture ● Query-builder database support ● Drivers for main DBMS systems (MySQL, MS SQL Server, Postgres, Oracle etc...) ● CSRF and XSS Filtering ● Session management ● Benchmarking
  • 6. Main features ● Image manipulation (requires GD, ImageMagick or NetPBM) ● Email library ● Uploading ● Caching ● CLI interface ● Internationalization ● … too many to be listed here.
  • 7. Architectural goals ● Dynamic instantiation: libraries and helpers are loaded by controllers on demand when they are needed, keeping the system light and reactive ● Components singularity: each class and its functions are highly autonomous in order to allow maximum usefulness ● Loose coupling: each component minimizes its reliance on other components, becoming more reusable.
  • 8. Requirements ● PHP 5.2.4 (5.4 is recommended) ● A Web Server Remind that, as of PHP 5.4, the interpreter provides a built-in web server to test your applications. So you do not really need a stand alone web server to start developing.
  • 9. application/config/config.php holds most of the configuration you need to start developing your application, such as base_url (e.g. http://google. com/, if Google was written with CI), URLs suffixes, default charsets, locales, hooks configuration, Composer integration and much more. Basic configuration
  • 10. Routing & Controllers Preliminar note: CI provides a index.php script which triggers the framework lifecycle for each request. To remove index.php from URL and to route every request to it, you can use mod_rewrite on Apache like this https://gist.github. com/sixpounder/c61e660b43c0aa2b9356 For PHP builtin server look at this GIST https://gist.github. com/sixpounder/6758cddd83330125bc10 From now on we assume index.php to be removed from URLs.
  • 11. Routing & Controllers A request lifecycle in CI
  • 12. Routing & Controllers CI URLs are basically query string arguments to index.php. They are made of URI segments that represent (by default, but this can be changed in application/config/config.php by defining custom routes) the controller and the method responsible for serving a request mapped on that specific URL.
  • 13. Routing & Controllers example.com/news/article/ID ● The first segment represents the controller class to be invoked ● The second segment represents the controller instance method that will be executed (assuming index if not specified) ● The third (and any further) segment represents an additional parameter that will be passed to the controller method as an argument.
  • 14. Routing & Controllers ● These URLs are SEO-friendly! ● You can organize controllers in sub folders. In this case, the initial URI segments will represent your folder structure. ● Classic query strings are available ● You can add URLs suffixes ● You can define overrides, custom URI routings and the default controller in application/config/routes.php
  • 15. Routing & Controllers Controller classes extend CI_Controller and must be placed in application/controllers. Class name must have its first letter capitalized and it must match the file name. /* application/controllers/Article.php */ class Article extends CI_Controller { … }
  • 16. Models are classes that interacts with your database. CI doesn’t provide an ORM like Rails Active Record, rather it provides a Query Builder that builds queries by masking the underlying physical DBMS implementation. Models
  • 17. Models ● Models should be indepent from the components that use them ● Query Builder supports transactions ● Database Forge Class can be used to manage the physical structure of your database (so you do not have the responsability to do so!) ● Support for migrations (by extending CI_Migration)
  • 18. Models To load and use a model inside a controller: $this->load->model(‘model_name’); Models must be placed in application/models. Classes and file names must have their first letter capitalized and the rest of the name lowercase. They must extend CI_Model.
  • 19. Views & Templating CI’s core provides different ways of sending an output to a client, like basic view rendering, simple template parsing and direct output control. All these methods are wrapped into core libraries.
  • 20. Views & Templating View rendering A view is simply a web page, or a page fragment, like a header, footer, sidebar, etc. In fact, views can flexibly be embedded within other views (within other views, etc., etc.) if you need this type of hierarchy. Views are stored by default in application/views directory and have .php extension (unless you need something different, eg. if you are using twig). A controller can render a view by loading it like this: $this->load->view(‘viewname’);
  • 21. Views & Templating View rendering Data is passed from the controller to the view by way of an array or an object in the second parameter of the view loading method. $data = array('title' => 'My Title','heading' => 'My Heading','message' => 'My Message'); $this->load->view('blogview', $data);
  • 22. Views & Templating View rendering A third boolean argument may be provided to the view loader. If it is present and its value is TRUE the method returns the string representation of the finalized view. This can be usefull for templating purposes. $data = array('title' => 'My Title','heading' => 'My Heading','body' => 'Article body'); var $content = $this->load->view('article', $data, TRUE);
  • 23. Views & Templating Output Library The Output Library is used under-the-hood by the view loader to finalize the output before sending it to the client. It can be directly used, for instance, to send a JSON output if you are dealing with a REST API, or a file’s content if you are writing a file server and so on.
  • 24. Views & Templating JSON example $this->output->set_content_type('application/json')->set_output(json_encode(array ('foo' => 'bar'))); Sending an image $this->output->set_content_type('jpeg')->set_output(file_get_contents ('files/something.jpg')); HINT: The _display() method is called automatically at the end of script execution, you won’t need to call it manually unless you are aborting script execution using exit() or die() in your code. Calling it without aborting script execution will result in duplicate output.
  • 25. Views & Templating Template Parser The Template Parser Library can parse simple templates by operating basic substitutions of pseudo-variables contained in your views. Pseudo variables must be enclosed in braces.
  • 26. Views & Templating Template Parser $this->load->library('parser'); $data = array( 'blog_title' => 'Six Blog', 'blog_heading' => 'A blog about computing', 'blog_entries' => array( array('title' => 'Title 1', 'body' => 'Body 1'), array('title' => 'Title 2', 'body' => 'Body 2'), array('title' => 'Title 3', 'body' => 'Body 3'), array('title' => 'Title 4', 'body' => 'Body 4'), array('title' => 'Title 5', 'body' => 'Body 5') ) ); // This could be the result of a query as well! $this->parser->parse(tpl', $data);
  • 28. Libraries & Helpers CI provides a bunch of libraries and helpers. We already saw the Output library (one of the few libraries that are auto loaded by CI itself), but there are many more.
  • 29. Libraries & Helpers Benchmarking Class Caching Driver Calendaring Class Shopping Cart Class Config Class Email Class Encrypt Class Encryption Library File Uploading Class Form Validation FTP Class Image Manipulation Class Input Class Javascript Class Language Class Loader Class Migrations Class Output Class Pagination Class Template Parser Class Security Class Session Library HTML Table Class Trackback Class Typography Class Unit Testing Class URI Class User Agent Class XML-RPC and XML-RPC Server Classes Zip Encoding Class
  • 30. Libraries & Helpers Helpers, as the name suggests, help you with tasks. Each helper file is simply a collection of functions in a particular category. There are URL Helpers, that assist in creating links, there are Form Helpers that help you create form elements, Text Helpers perform various text formatting routines, Cookie Helpers set and read cookies, File Helpers help you deal with files, etc
  • 31. Libraries & Helpers Array Helper CAPTCHA Helper Cookie Helper Date Helper Directory Helper Download Helper Email Helper File Helper Form Helper HTML Helper Inflector Helper Language Helper Number Helper Path Helper Security Helper Smiley Helper String Helper Text Helper Typography Helper URL Helper XML Helper
  • 32. Extending CodeIgniter CI provides many ways to extend the framework ● Custom libraries ● Estensione system libraries ● Hooks ● Sparks plugins ( http://getsparks.org/ ) ● Easy integration with Composer
  • 33. Extending CodeIgniter You can replace or extend the system libraries provided by CI. To replace them with your own implementation,simply create a library with the same name as the one you want to replace in application/libraries. To extend them, create a new class prefixed by the default extender prefix (see application/config/config.php), like this: class MY_Email extends CI_Email { … }
  • 34. Extending CodeIgniter With hooks you can tap into the framework core and modify its behaviour without hacking the core files
  • 35. Extending CodeIgniter Defining a hook in application/config/hooks.php each key in $hook represents a script at a certain point of the application lifecycle: $hook['pre_controller'] = array( 'class' => 'MyClass', 'function' => 'Myfunction', 'filename' => 'Myclass.php', 'filepath' => 'hooks', 'params' => array('beer', 'wine', 'snacks') ); Available hook points are: pre_system, pre_controller, post_controller_constructor, post_controller, display_override, cache_override, post_system.
  • 36. Q & A