【问题标题】:Callback codeigniter can't access回调codeigniter无法访问
【发布时间】:2020-04-10 06:40:02
【问题描述】:

我有一个控制器

function append_bukti()
{
    $this->load->library('form_validation');
    $this->load->helper('file');

    $this->form_validation->set_rules('nomor_nota', 'Nomor Nota', 'trim|required');
    $this->form_validation->set_rules('jumlah_tagihan', 'Jumlah Tagihan', 'trim|required');
    $this->form_validation->set_rules('date_payment', 'Tanggal Pembayaran', 'trim|required');
    $this->form_validation->set_rules('file', '', 'callback__file_check');

    if ($this->form_validation->run()){

        $er="bener";
        echo json_encode($er);
    }else{
        $array = array(
            'error'                 => true,
            'nomor_nota_error'      => form_error('nomor_nota'),
            'jumlah_tagihan_error'  => form_error('jumlah_tagihan'),
            'date_payment_error'    => form_error('date_payment'),
            'file_error'            => form_error('file'),
            'validasi'              => $this->form_validation->run()
        );
    }   
    echo json_encode($array);
}

这里是函数回调

public function _file_check($str){
    $allowed_mime_type_arr  = array('image/png','image/x-png');
    $mime                   = get_mime_by_extension($_FILES['file']['name']);

    if(isset($_FILES['file']['name']) && $_FILES['file']['name']!=""){
        if(in_array($mime, $allowed_mime_type_arr)){
            return true;
        }else{
            $this->form_validation->set_message('file_check', 'Silahkan pilih hanya file pdf/gif/jpg/png.');
            return false;
        }
    }else{
        $this->form_validation->set_message('file_check', 'Silakan pilih file untuk diupload.');
        return false;
    }
}

如果我运行此函数,则无法处理,什么也没有。如果所有形式都为真,为什么我回显 $this->validation->run() 仍然回显假。我需要你的帮助。干杯

【问题讨论】:

    标签: php ajax codeigniter


    【解决方案1】:
    'validasi'  => $this->form_validation->run()
    

    这一行使函数递归并且永远不会结束。只需将其设置为false

                'validasi'  => false
            );
           echo json_encode($array); //put this statement into the else scope
        }   
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-12
      • 1970-01-01
      • 2016-06-12
      相关资源
      最近更新 更多