Real
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
765
On Slideshare
765
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
3
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1.
  • 2. Real World Web App Development(in 2 hours or less)
    GT College of Computing
    October 13, 2010
    Jason Ardell
    Joshua Silver
  • 3. What do we mean, “Real World”Web App Development?
  • 4. What are we building?(Demo)
  • 5. Who are we?
    Joshua Silver
    @1yellowbrick
    Joshua.silver@securehealthpay.com
    CS ‘09
    Jason Ardell
    @ardell
    ardell@gmail.com
    CS ‘05
  • 6.
  • 7. Our Toolkit Today
  • 8. What is MVC and why use it?
  • 9. http://betterexplained.com/articles/intermediate-rails-understanding-models-views-and-controllers/
  • 10. InteractiveFollow along at:http://github.com/joshuasilver/RealWorldWebApp
  • 11.
  • 12. Connect to Server
    You should have credentials
    http://dl.dropbox.com/u/5037034/gt.txt
    $> ssh root@[your.ip.address]
    [enter password]
  • 13. 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>
  • 14. Setup DB
    cd /var/www/cakephp
    nano db_schema.sql
    (Be sure to use spaces, not tabs)
  • 15. 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)
  • 16. Insert Fake Data
    cd /var/www/cakephp
    nano db_testdata.sql
    (Be sure to use spaces, not tabs)
  • 17. 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)
  • 18. Done with MySQLOver to CakePHP … its already installed
    cd /var/www/cakephp
  • 19. Tour of CakePHP
    All we care about is:
    /app/models/
    /app/views/
    /app/controllers/
  • 20. A few notes
    For automagic to work, you must name your files exactly to the spec. (case and spacing sensitive)
  • 21. Create a student model
    # nano /var/www/cakephp/app/models/student.php
    <?php
    class Student extends AppModel {
    var $name = 'Student';
    }
    // CakePHPautomagically completes the rest
    ?>
  • 22. 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'));  }
    }
    ?>
  • 23. Views
    Class name
    Method Names
  • 24. Create student view folder
    # mkdir /var/www/cakephp/app/views/students
  • 25. 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
  • 26. http://{ip_address}/students/index
    Method
    Controller
  • 27.
  • 28. 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
  • 29. 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'));
    }
    }
    }
  • 30. 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)
  • 31.
  • 32. Twilio