Real
-
Upload
joshua-silver -
Category
Technology
-
view
629 -
download
1
Transcript of Real
![Page 1: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/1.jpg)
![Page 2: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/2.jpg)
Real World Web App Development(in 2 hours or less)
Jason ArdellJoshua Silver
GT College of ComputingOctober 13, 2010
![Page 3: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/3.jpg)
What do we mean,
“Real World”Web App Development?
![Page 4: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/4.jpg)
What are we building?
(Demo)
![Page 6: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/6.jpg)
![Page 7: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/7.jpg)
Our Toolkit Today
![Page 8: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/8.jpg)
What is MVC and why use it?
![Page 9: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/9.jpg)
http://betterexplained.com/articles/intermediate-rails-understanding-models-views-and-controllers/
![Page 10: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/10.jpg)
Interactive
Follow along at:
http://github.com/joshuasilver/RealWorldWebApp
![Page 11: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/11.jpg)
![Page 12: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/12.jpg)
Connect to Server
• You should have credentials
• http://dl.dropbox.com/u/5037034/gt.txt$> ssh root@[your.ip.address]
[enter password]
![Page 13: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/13.jpg)
Connect to MySQLOnce logged in, from Command line:
# mysql -u cakephpuser -p cakephpdbEnter password: << PASSWORD IS: foo
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 183Server version: 5.1.41-3ubuntu12.6-log (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
![Page 14: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/14.jpg)
Setup DB
(Be sure to use spaces, not tabs)
cd /var/www/cakephpnano db_schema.sql
![Page 15: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/15.jpg)
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)
Make sure it worked
![Page 16: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/16.jpg)
Insert Fake Data
(Be sure to use spaces, not tabs)
cd /var/www/cakephpnano db_testdata.sql
![Page 17: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/17.jpg)
Make sure it workedmysql> 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)
![Page 18: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/18.jpg)
Done with MySQL
Over to CakePHP … its already installed
cd /var/www/cakephp
![Page 19: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/19.jpg)
Tour of CakePHP
All we care about is:
/app/models//app/views//app/controllers/
![Page 20: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/20.jpg)
A few notes
• For automagic to work, you must name your files exactly to the spec. (case and spacing sensitive)
![Page 21: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/21.jpg)
Create a student model# nano /var/www/cakephp/app/models/student.php
<?php
class Student extends AppModel { var $name = 'Student';}
// CakePHP automagically completes the rest
?>
![Page 22: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/22.jpg)
Create a student controller# nano
/var/www/cakephp/app/controllers/students_controller.php
<?phpclass StudentsController extends AppController {
var $name = 'Students'; function index() {
$this->set('studentList', $this->Student->find('all'));
}}
?>
![Page 23: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/23.jpg)
Views
Class name
Method Names
![Page 24: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/24.jpg)
Create student view folder# mkdir /var/www/cakephp/app/views/students
![Page 25: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/25.jpg)
Add index view
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 -->
<?php foreach ($studentList as $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> <?php endforeach; ?></table>
![Page 26: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/26.jpg)
http://{ip_address}/students/index
ControllerMethod
![Page 27: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/27.jpg)
![Page 28: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/28.jpg)
Let’s figure out how to add a student
1.) Add new method called “add” to students_controller
2.) Make associated view3.) Add link on homepage to add a student
![Page 29: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/29.jpg)
nano /var/www/cakephp/app/controllers/students_controller.php
<?phpclass 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')); } } }
![Page 30: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/30.jpg)
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)
![Page 31: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/31.jpg)
![Page 32: Real](https://reader036.fdocuments.in/reader036/viewer/2022062513/55639153d8b42adf7a8b5517/html5/thumbnails/32.jpg)
Twilio