• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Real
 

Real

on

  • 640 views

 

Statistics

Views

Total Views
640
Views on SlideShare
640
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Real Real Presentation Transcript

    • Real World Web App Development(in 2 hours or less)
      GT College of Computing
      October 13, 2010
      Jason Ardell
      Joshua Silver
    • What do we mean, “Real World”Web App Development?
    • What are we building?(Demo)
    • Who are we?
      Joshua Silver
      @1yellowbrick
      Joshua.silver@securehealthpay.com
      CS ‘09
      Jason Ardell
      @ardell
      ardell@gmail.com
      CS ‘05
    • Our Toolkit Today
    • What is MVC and why use it?
    • http://betterexplained.com/articles/intermediate-rails-understanding-models-views-and-controllers/
    • InteractiveFollow along at:http://github.com/joshuasilver/RealWorldWebApp
    • Connect to Server
      You should have credentials
      http://dl.dropbox.com/u/5037034/gt.txt
      $> ssh root@[your.ip.address]
      [enter password]
    • Connect to MySQL
      Once logged in, from Command line:
      # mysql -u cakephpuser -p cakephpdb
      Enter password: << PASSWORD IS: foo
      Welcome to the MySQL monitor. Commands end with ; or g.
      Your MySQL connection id is 183
      Server version: 5.1.41-3ubuntu12.6-log (Ubuntu)
      Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
      mysql>
    • Setup DB
      cd /var/www/cakephp
      nano db_schema.sql
      (Be sure to use spaces, not tabs)
    • Make sure it worked
      mysql> source db_schema.sql
      mysql> show tables;
      +---------------------+
      | Tables_in_cakephpdb |
      +---------------------+
      | students |
      +---------------------+
      1 row in set (0.00 sec)
      mysql> describe students;
      +--------------+------------------+------+-----+-------------------+----------------+
      | Field | Type | Null | Key | Default | Extra |
      +--------------+------------------+------+-----+-------------------+----------------+
      | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
      | first_name | varchar(50) | NO | | NULL | |
      | last_name | varchar(50) | NO | | NULL | |
      | phone_number | char(12) | NO | | NULL | |
      | time_created | timestamp | NO | | CURRENT_TIMESTAMP | |
      +--------------+------------------+------+-----+-------------------+----------------+
      5 rows in set (0.01 sec)
    • Insert Fake Data
      cd /var/www/cakephp
      nano db_testdata.sql
      (Be sure to use spaces, not tabs)
    • Make sure it worked
      mysql> source db_testdata.sql
      mysql> select * from students;
      +----+------------+-----------+--------------+---------------------+
      | id | first_name | last_name | phone_number | time_created |
      +----+------------+-----------+--------------+---------------------+
      | 1 | John | Doe | 678-555-0000 | 2010-10-13 16:08:22 |
      | 2 | Sally | Smith | 770-555-1234 | 2010-10-13 16:08:23 |
      +----+------------+-----------+--------------+---------------------+
      2 rows in set (0.00 sec)
    • Done with MySQLOver to CakePHP … its already installed
      cd /var/www/cakephp
    • Tour of CakePHP
      All we care about is:
      /app/models/
      /app/views/
      /app/controllers/
    • A few notes
      For automagic to work, you must name your files exactly to the spec. (case and spacing sensitive)
    • Create a student model
      # nano /var/www/cakephp/app/models/student.php
      <?php
      class Student extends AppModel {
      var $name = 'Student';
      }
      // CakePHPautomagically completes the rest
      ?>
    • Create a student controller
      # nano /var/www/cakephp/app/controllers/students_controller.php
      <?php
      class StudentsController extends AppController {
        var $name = 'Students';
        function index() {    $this->set('studentList',
      $this->Student->find('all'));  }
      }
      ?>
    • Views
      Class name
      Method Names
    • Create student view folder
      # mkdir /var/www/cakephp/app/views/students
    • nano /var/www/cakephp/app/views/students/index.ctp
      root@gt-tutorial-jos
      <h1>Students</h1>
      <table>
      <tr>
      <th>Id</th>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Phone Number</th>
      <th>Created</th>
      </tr>
      <!-- Here is where we loop through our $students array,
      printing out the students -->
      <?phpforeach ($studentListas $student): ?>
      <tr>
      <td><?php echo $student['Student']['id']; ?></td>
      <td><?php echo $student['Student']['first_name']; ?></td>
      <td><?php echo $student['Student']['last_name']; ?></td>
      <td><?php echo $student['Student']['phone_number']; ?></td>
      <td><?php echo $student['Student']['time_created']; ?></td>
      </tr>
      <?phpendforeach; ?>
      </table>
      Add index view
    • http://{ip_address}/students/index
      Method
      Controller
    • Let’s figure out how to add a student
      1.) Add new method called “add” to students_controller
      2.) Make associated view
      3.) Add link on homepage to add a student
    • nano /var/www/cakephp/app/controllers/students_controller.php
      <?php
      class StudentsController extends AppController {
      var $name = 'Students';
      function index() {
      $this->set('studentList', $this->Student->find('all'));
      }
      function add() {
      if (!empty($this->data)) {
      if ($this->Student->save($this->data)) {
      $this->Session->setFlash('Your student has been added.');
      $this->redirect(array('action' => 'index'));
      }
      }
      }
    • Add view
      <h1>Add Student</h1>
      <?php
      echo $form->create('Student');
      echo $form->input('first_name');
      echo $form->input('last_name');
      echo $form->input('phone_number');
      echo $form->end('Add Student');
      ?>
      <?php echo $html->link("Add Student", array('controller' => 'students', 'action' => 'add')); ?>
      Add link on homepage (index.ctp)
    • Twilio