2. ïŸ Introduction
ï Why Framework not Scratch?
ï MVC ( Model View Controller) Architecture
ï What is CodeIgniter ????
ïŸ Application Flow of CodeIgniter
ï CodeIgniter URL
ï Controllers
ï Views
ï Models
ïŸ CRUD operations
ïŸ Session starting
ïŸ Form validation
ïŸ Q/A
ïŸ Reference
3. ï Key Factors of a Development
ï Interface Design
ï Business Logic
ï Database Manipulation
ï Advantage of Framework
ï 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
4. ï± 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
5. ï¶ An Open Source Web Application Framework
ï¶ Nearly Zero Configuration
ï¶ MVC ( Model View Controller ) Architecture
ï¶ Multiple DB (Database) support
ï¶ Caching
ï¶ Modules
ï¶ Validation
ï¶ Rich Sets of Libraries for Commonly Needed Tasks
ï¶ Has a Clear, Thorough documentation
7. URL in CodeIgniter is Segment Based.
www.your-site.com/news/article/my_article
Segments in a URI
www.your-site.com/class/function/ID
CodeIgniter Optionally Supports Query String URL
www.your-site.com/index.php?c=news&m=article&ID=345
8. A Class file resides under âapplication/controllersâ
www.your-site.com/index.php/first
<?php
class First extends CI_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();â
9. In This Particular Code
www.your-site.com/index.php/first/bdosdn/world
<?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 !!â
âą Note:
âą The âIndexâ Function always loads by default. Unless there is a second
segment in the URL
10. ï A Webpage or A page Fragment
ï Should be placed under âapplication/viewsâ
ï Never Called Directly
10
web_root/myci/system/application/views/myview.php
<html>
<title> My First CodeIgniter Project</title>
<body>
<h1> Welcome ALL ⊠To My .. ::: First Project ::: .
. . </h1>
</body>
</html>
11. Calling a VIEW from Controller
$this->load->view(âmyviewâ);
Data Passing to a VIEW from Controller
function index() {
$var = array(
âfull_nameâ => âAmzad Hossainâ,
âemailâ => âtohi1000@yahoo.comâ
);
$this->load->view(âmyviewâ, $var);
}
<html>
<title> ..::Personal Info::.. </title>
<body>
Full Name : <?php echo $full_name;?> <br />
E-mail : <?=email;?> <br />
</body>
</html>
12. Designed 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();
16. CONFIGURATION
Then open application/config/config.php
$config['base_url'] = 'http://localhost/ci_user';
Open application/config/autoload.php
$autoload['libraries'] = array('session','database');
$autoload['helper'] = array('url','form');
Open application/config/routes.php, change
default controller to user controller
17. Creating our view page
Create a blank document in the views file (application ->
views) and name it Registration.php /Login.php
Using HTML and CSS create a simple registration
form