0

我一直在试图弄清楚如何使用这些闪存数据。记得上次有困难,这次又好像忘记了什么。

所以基本上,我试图在某个地方设置一个 flasherror:

if(!$this->paypal_pro->APICallSuccessful($PayPalResult['ACK']))
  {
       $this->session->set_flashdata('flashError',  
           array('Errors'=>$PayPalResult['ERRORS']));
       redirect('main/form');
  } 

在我的主要/形式中,我得到了:

function Form()
 {
// Process validation form
 if ($this->form_validation->run() == FALSE)
 {
      //IF the validation process hasn't been run or there are validation errors
       $this->parser->parse('template/template', $data);
 } 

在那个观点中,我试图得到那个 flashError :

<?php if($this->session->flashdata('flashError')):?>
  <div class='flashError'>
 <?php  
  $flashError=$this->session->flashdata('flashError');
  foreach( $flashError['Errors'] as $Error) {
     echo $Error['L_SHORTMESSAGE'].' ('.$Error['L_ERRORCODE'].'):';
     echo '<br/>';
     echo $Error['L_LONGMESSAGE'];
  }
 ?>
  </div>
 <?php endif?> 

我在该变量中没有任何内容,当我尝试对其进行 var_dump 时,它返回错误。

尽管官方文档说“仅可用于下一个服务器请求,然后自动清除”,但有人可以解释我如何使用它</p>

4

2 回答 2

0

来自 Codeigniters 文档:

如果您发现需要通过附加请求保留 flashdata 变量,则可以使用 keep_flashdata() 函数执行此操作。

$this->session->keep_flashdata('item');

更新:

问题似乎在这里:

$this->session->set_flashdata('flashError',  
           array('Errors'=>$PayPalResult['ERRORS']));

Try this one:

$this->session->set_flashdata(array('Errors'=>$PayPalResult['ERRORS']));
于 2012-08-02T06:55:39.883 回答
0

As you are doing

if($this->session->flashdata('flashError'))

You are actually removing the flashError item, as it has been read.

What you need to do, is as you have a little further down, assign it to a variable and then do your checks.

于 2012-08-02T07:05:43.053 回答