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 . Your MySQL connection id is 183 Server version: 5.1.41-3ubuntu12.6-log (Ubuntu) Type 'help;' or '' for help. Type '' 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)
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')); } } ?>
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')); } } }