2. Who is Hanafiah Yahya?
● Muhamad Hanafiah Bin Yahya
● Digital Immigrants generations
● Started programming, 1997 - MIRC script, VBA, Pascal,
● https://my.linkedin.com/in/hanafiahyahya
5. Kreydle Academy
● CSR - Corporate social responsibility
● Non profit initiative…
● We contribute back to community
● Helping Graduates Gain the competitive
edge
● fill in the gap between university and what
industry really want
● Its free for student
6. Kreydle Academy
● Want to contribute?
● Help us spread the word. share with your
friends on twitter, facebook, blog and any
medium that you have
● or Join us as guest speaker
http://www.kreydle.com/academy/
21. Spaghetti Code
1) Spaghetti code is a specific [ goto 8 ]
2) written in order, but splattered [ goto 9 ]
3) allowed to jump to a specific [ goto 7 ]
4) the goto statement, which [ goto 3 ]
5) a set of instructions is not [ goto 2 ]
6) spaghetti. It often refers to [ goto 4 ]
7) line of code. [ end ]
8) kind of bad coding, where [ goto 5 ]
9) all over the place ( like a knotted [ goto 6 ] )
33. Topics
1. Spaghetti Code
2. MVC introduction
3. PHP MVC frameworks
4. Working with CodeIgniter
5. Config
6. Model
7. View
8. Controller
9. Continue your journey
34. History
Invented in 1979 by Smalltalk programmers,
Trygve Reenskaug
It is software design pattern
http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-index.html
35. History
1979?.. so old
Made popular by Ruby On Rails
initial release on 2005 and
adapted by PHP community
https://upload.wikimedia.org/...n_Rails.svg.png
49. Topics
1. Spaghetti Code
2. MVC introduction
3. PHP MVC frameworks
4. Working with CodeIgniter
5. Config
6. Model
7. View
8. Controller
9. Continue your journey
50. Why CodeIgniter
Why not CakePHP or Laravel or Symfony or
FuelPHP or YII or Zend Framework or Kohana
or Zoop or Akelos or PHP on Trax or Prado or
Seagull or …?
52. That being said, CI is
not dead!
● easy to understand
● simple, doesn't require advance OOP
● quick to get up and running
● good docs
53. CodeIgniter is a powerful PHP framework with
a very small footprint, built for developers who
need a simple and elegant toolkit to create full-
featured web applications.
CodeIgniter
http://www.codeigniter.com
63. <?php
public function get_users()
{
$query = $this->db->get('users');
return $query->result();
}
<?php
// Get all users
$stmt = $dbh->prepare("SELECT * FROM users");
$stmt->setFetchMode(PDO::FETCH_ASSOC);
if ($stmt->execute()) {
while ($row = $stmt->fetch()) {
Model - Get all users
64. <?php
public function insert()
{
$this->name = $this->input->post('name'); //
similar to $_POST['name'];
$this->age = $this->input->post('age');
$this->email = $this->input->post('email');
$this->db->insert('users', $this);
}
<?php
$stmt = $dbh->prepare("INSERT INTO users ( name,
age, email ) values ( :name, :age, :email )");
$stmt->bindParam(':name', $name, PDO::PARAM_STR);
$stmt->bindParam(':age', $age, PDO::PARAM_INT);
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$name = $_POST['name'];
$age = $_POST['age'];
$email = $_POST['email'];
$stmt->execute();
Model - Add new user
65. <?php
public function update()
{
$this->name = $this->input->post('name'); //
similar to $_POST['name'];
$this->age = $this->input->post('age');
$this->email = $this->input->post('email');
$this->db->update('users', $this, array('id' =>
$this->input->post('id')));
}
<?php
$stmt = $dbh->prepare("UPDATE users SET name = :
name, age = :age, email = :email WHERE id = :id");
$stmt->bindParam(':name', $name, PDO::PARAM_STR);
$stmt->bindParam(':age', $age, PDO::PARAM_INT);
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$name = $_POST['name'];
$age = $_POST['age'];
$email = $_POST['email'];
$id = $_POST['id'];
$stmt->execute();
Model - Edit user
66. <?php
public function delete($id = FALSE)
{
$this->db->delete('users', array('id' => $id));
}
<?php
$stmt = $dbh->prepare("DELETE FROM users WHERE id =
:id LIMIT 1");
$stmt->bindParam(':id', $id, PDO::PARAM_STR);
$id = $_GET['delete'];
$stmt->execute();
Model - Delete user