繁体   English   中英

如何在Codeigniter中使用重定向传递数据

[英]How to Pass data by using redirect in codeigniter

我是CodeIgniter的新手。 我正在尝试实现stripe payment gateway integration 付款成功状态正常。 我尝试向用户显示失败时的内容。 但是将故障数据传递到我的视图无法正常工作。 下面是我的代码。

 public function stripepay()
    {
    // some post variables
    try {
    require_once APPPATH."third_party/stripe/init.php";
    //set api key
    $stripe = array(
    "secret_key"      => "sk_test_gSev8A4OJf0F3BXXXXXXXX",
    "publishable_key" => "pk_test_XZZxorO1rYsZTJXXXXXXXX"
    );
    \Stripe\Stripe::setApiKey($stripe['secret_key']);
    // some more code
    }catch ( Stripe\Error\Base $e )
    {
    // Code to do something with the $e exception object when an error occurs.
    $body = $e->getJsonBody();
    $err  = $body['error'];
    $data['failure_response'] = $err;
    $data['response_status'] = $e->getHttpStatus();
    $where = array('id' => $this->session->userdata('id'));
    $payment_info = $this->baseM->getOneRowData('users', $where);
    // this redirct is not working 
    //redirect('service/failure_402'.$data);
    }
    }

当它进入此catch块时,我试图重定向到failue402视图。

public function failure_402($data)
{
$where = array('id' => $this->session->userdata('id'));
$payment_info = $this->baseM->getOneRowData('users', $where);
$this->load->view('page_layout/header', $data);
$this->load->view('service/failure_402',$data);
$this->load->view('page_layout/footer', $data); 
}

In the above stripePay() function 
// this redirect is not working 
redirect('service/failure_402'.$data); 
is not working.

请指导我在哪里我做错了。 任何帮助将不胜感激。

您可以使用codeigniter会话的set_flashdata()方法

{

$body = $e->getJsonBody();
$err  = $body['error'];
$data['failure_response'] = $err;
$data['response_status'] = $e->getHttpStatus();
$where = array('id' => $this->session->userdata('id'));
$payment_info = $this->baseM->getOneRowData('users', $where);

/* EITHER */
$this->session->set_flashdata('failure_response' ,$err);
$this->session->set_flashdata('failure_response' ,$e->getHttpStatus());
/* OR */
 $this->session->set_flashdata($data);

 redirect('service/failure_402');
}

falure_402()

public function failure_402()
{
   print_r($this->session->flashdata());
   /*OR this way */
  echo $this->session->flashdata('failure_response')
}

有关更多信息: https : //www.codeigniter.com/user_guide/libraries/sessions.html#flashdata

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM