退会処理
最後に退会の処理を作ります。 アクション delete() のままでもいいんですが、お客さんに delete ってのもどうかと思ったので、 leave にしてみました。
function leave() {
if (!$this->Session->check('Member.id')) {
$this->redirect(array('action'=>'login'));
}
if (!empty($this->data)) {
if ($this->Member->delete($this->Session->read('Member.id'))) {
$this->Session->destroy();
$this->render('quit');
} else {
$this->Session->setFlash(__('退会できませんでした', true));
}
} else {
$this->data = $this->Member->read(null, $this->Session->read('Member.id'));
$this->set('member', $this->data);
}
$types = $this->Member->Type->find('list');
$favorites = $this->Member->Favorite->find('list');
$this->set(compact('types', 'favorites'));
}
また、 confirm.ctp をコピーしてきて改造します。フォームの始まりと終わりの部分だけ書き換えます。
<?php echo $javascript->link(array('jquery','util'), false); ?>
<div class="members view">
<?php echo $this->Form->create(null, array('url'=>'/members/leave'));?>
<?php echo $this->Form->input('id');?>
・
・
・
<div class="submit">
<?php echo $this->Form->button('戻る', array('type'=>'button', 'id'=>'back_button')); ?>
</div>
<?php echo $this->Form->end('退会する'); ?>
</div>
ここで id=’back_button’ というのを作ったので、これも javascript の util.js に追加しておきます。
$('#back_button').click(function(){
history.back();
});
戻れればいいだけなので、ただのヒストリーバックです。
退会の完了画面用にビューで quit.ctp を用意しておきます。
