2016-10-08 5 views
0

flashdataの配列に問題があります。私はcodeigniterに変更しましたが、動作しません。flashdata codeigniter配列

コントローラコード:

function reply(){ 
    $id = $this->input->post('id'); 

    $err = array(); 

    if(!$_POST['msg']) { 
     $err[] = 'all the fields must be filled in!'; 
    } 

    else if(!count($err)){ 
     $data = array(
      'DestinationNumber'=> $this->input->post('hp'), 
      'TextDecoded'=> $this->input->post('msg'), 
      'i_id'=> $this->input->post('id')); 

     $this->inbox_model->reply($data); 

     if($data >= 1) { 
      $this->session->set_flashdata['msg']['success']='Send Success!'; 
     } 

     else { 
      $err[] = 'Send Failed!'; 
     } 

    } 

    if(count($err)){ 
     $this->session->set_flashdata['msg']['err'] = implode('<br />',$err); 
    } 

    redirect('sms/inbox/read/'.$id); 
} 

ビューコード:

if($this->session->flashdata['msg']['err']){ 
    echo "<div class='alert alert-danger alert-dismissible'> 
      <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button> 
      ".$this->session->flashdata['msg']['err']."</div>"; 
      $this->session->unset_flashdata['msg']['err']; 
}      
if($this->session->flashdata['msg']['success']){ 
    echo "<div class='alert alert-success alert-dismissible'> 
      <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button> 
      ".$this->session->flashdata['msg']['success']."</div>"; 
      $this->session->unset_flashdata['msg']['success']; 
} 

が私を助けることができますか?

+0

なぜそれが機能しないのですか?どんな種類のエラーや出力がありますか?より良い回答を得るためにできるだけ多くの情報を提供してください。 – yivi

+0

エラーはありません。別のコードが正常に動作し、フラッシュデータのみが表示されません。 – Kurro

+0

ウェブサーバーのログを確認しましたか? – yivi

答えて

0

コントローラー:

$err = array(); 
if(!$_POST['msg']) { 
$err['msg_err'] = '<strong>Oh snap!</strong> all the fields must be filled in';} 

ビュー:

if($this->session->flashdata('err')){ 
echo "<div class='alert alert-danger alert-dismissible'> 
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button> 
".$this->session->flashdata('err')['msg_err']."</div>"; } 
3

あなたは

$array_msg = array('first'=>'<p>msg 1</p>','second'=>'<p>msg2</p>'); 

その後、簡単な方法を使用してセッションをflashdataする配列を設定してアクセス

$this->session->set_flashdata('msg',$array_msg); 

そのセッションにそれを渡すことができ、それ

$msg = $this->session->flashdata('msg'); 
echo $msg['first']; 
+0

haii、ヒントを与えてくれてありがとう、ちょっとした修正でコードは今、コード: – Kurro