#最終回
いきなり最終回(^_^;)
とりあえず予約の登録ができたら、管理機能を除けばほぼ出来上がりなので、
一気に作ってしまいました。
reserves_controller.php
<?php class ReservesController extends AppController { var $name = 'Reserves'; var $uses = array('User','Seminar','Reserve'); function delete($uid,$sid){ print_r ($this->Reserve->delReserve($uid,$sid)); $this->flash(' uid: '.$uid.' sid: '.$sid.' の予約は削除されました。','/users/index/'); } function add($uid,$sid){ print_r ($this->Reserve->addReserve($uid,$sid)); $this->flash(' uid: '.$uid.' sid: '.$sid.' の予約を行いました。','/users/index/'); } } ?>
reserve.php
<?php class Reserve extends AppModel { var $name = 'Reserve'; var $useTable = 'seminars_users'; var $belongsTo = array('Seminar','User'); function addReserve($uid,$sid){ $ret = $this->query("insert into seminars_users (user_id,seminar_id) values($uid,$sid)"); return $ret; } function delReserve($uid,$sid){ $ret = $this->query("delete FROM seminars_users WHERE user_id = $uid and seminar_id=$sid"); return $ret; } } ?>
index.thtml
<div id="mainbar"> <h3>今後の開催予定セミナー</h3> <table> <tr> <th> セミナー </th> <th> 開始日 </th> <th> 終了日 </th> <th> 定員 </th> <th> 費用 </th> <th> --- </th> </tr> <?php foreach ($seminar_list as $semi): ?> <tr> <td> <?php echo $semi['Seminar']['name']; ?> </td> <td> <?php echo $semi['Seminar']['sstart']; ?> </td> <td> <?php echo $semi['Seminar']['send']; ?> </td> <td> <?php echo $semi['Seminar']['snumber']; ?> </td> <td> <?php echo $semi['Seminar']['cost']; ?> </td> <td> <?php echo $html->link( '予約', "/reserves/add/{$me['User']['id']}/{$semi['Seminar']['id']}", null, '本当に予約しますか?' )?> </td> </tr> <?php endforeach; ?> </table> <h3> <?php echo $auth['name']."さんが予約しているセミナー"; ?> </h3> <table> <tr> <th> セミナー </th> <th> 開始日 </th> <th> 終了日 </th> <th> 定員 </th> <th> 費用 </th> <th> --- </th> </tr> <?php foreach ($me['Seminar'] as $seminar): ?> <tr> <td> <?php echo $seminar['name']; ?> </td> <td> <?php echo $seminar['sstart']; ?> </td> <td> <?php echo $seminar['send']; ?> </td> <td> <?php echo $seminar['snumber']; ?> </td> <td> <?php echo $seminar['cost']; ?> </td> <td> <?php echo $html->link( 'キャンセル', "/reserves/delete/{$me['User']['id']}/{$seminar['id']}", null, '本当にキャンセルしますか' )?> </td> </tr> <?php endforeach; ?> </table> <h3>My Profile</h3> <p><?= $me['User']['profile']; ?></p> </div>
途中色々ありましたが、まあなんとか基本はマスターできたような感じです。
これからは、積極的にcakePHPを利用していきたいと思います。