Real

730 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
730
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Real

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

×