如果出错退出函数- cakephp


exit function if error - cakephp

我有一个函数来检查信用卡是否有效。如果是,则继续将表单中的详细信息输入数据库。但如果不是,则显示传递的消息。

问题是,如果信用卡有问题,则传递消息,而不是退出函数,因此它不会尝试继续从表单中添加数据,而是添加数据。

我不知道如何停下来。下面的代码是为我编写的,似乎创建了一个新的分派,并试图返回到前面的函数confirm。

function confirm() {
    //This view contains the form, when user submits they go to checkout view
    if (isset($data)){$this->data = $data;}
    $this->set('redirect_to', 'checkout');  
}
function checkout(){
   if(!empty($this->data['User']['card_number'])){
        $check_card = $this->BillingValidation->validate_card($this->data['User']['card_number']);
        if($check_card['valid']!=false){
            // card is valid !
        } else {        
            $msg[0][] = $check_card['error'];
            $flashmsg = implode('<br />',$msg[0]).implode('<br />',$msg[1]);
                $this->Session->setFlash(__($flashmsg,
                          true),'default', array('class' => 'flash-message-success'));
            //if credit card is invalid go back to confirm view
            $this->autoRender = false;
            $d = new Dispatcher();
            $d->dispatch(array("controller" => "res", "action" => "confirm"),array("data" => $this->data));
        }
    } 
          //if credit card ok then continues to process form
}

我使用exit(),这似乎工作